184d30d9dStsutsui/* $NetBSD: x68kGraph.c,v 1.4 2020/11/05 16:06:08 tsutsui Exp $ */ 2706f2543Smrg/*------------------------------------------------------------------------- 3706f2543Smrg * Copyright (c) 1996 Yasushi Yamasaki 4706f2543Smrg * All rights reserved. 5706f2543Smrg * 6706f2543Smrg * Redistribution and use in source and binary forms, with or without 7706f2543Smrg * modification, are permitted provided that the following conditions 8706f2543Smrg * are met: 9706f2543Smrg * 1. Redistributions of source code must retain the above copyright 10706f2543Smrg * notice, this list of conditions and the following disclaimer. 11706f2543Smrg * 2. Redistributions in binary form must reproduce the above copyright 12706f2543Smrg * notice, this list of conditions and the following disclaimer in the 13706f2543Smrg * documentation and/or other materials provided with the distribution. 14706f2543Smrg * 15706f2543Smrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16706f2543Smrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17706f2543Smrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18706f2543Smrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19706f2543Smrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20706f2543Smrg * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21706f2543Smrg * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22706f2543Smrg * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23706f2543Smrg * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24706f2543Smrg * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25706f2543Smrg *-----------------------------------------------------------------------*/ 26706f2543Smrg 27706f2543Smrg/* $XConsortium: sunCfb.c,v 1.15.1.2 95/01/12 18:54:42 kaleb Exp $ */ 28706f2543Smrg 29706f2543Smrg/* 30706f2543SmrgCopyright (c) 1990 X Consortium 31706f2543Smrg 32706f2543SmrgPermission is hereby granted, free of charge, to any person obtaining a copy 33706f2543Smrgof this software and associated documentation files (the "Software"), to deal 34706f2543Smrgin the Software without restriction, including without limitation the rights 35706f2543Smrgto use, copy, modify, merge, publish, distribute, sublicense, and/or sell 36706f2543Smrgcopies of the Software, and to permit persons to whom the Software is 37706f2543Smrgfurnished to do so, subject to the following conditions: 38706f2543Smrg 39706f2543SmrgThe above copyright notice and this permission notice shall be included in 40706f2543Smrgall copies or substantial portions of the Software. 41706f2543Smrg 42706f2543SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 43706f2543SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 44706f2543SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 45706f2543SmrgX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 46706f2543SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 47706f2543SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 48706f2543Smrg 49706f2543SmrgExcept as contained in this notice, the name of the X Consortium shall not be 50706f2543Smrgused in advertising or otherwise to promote the sale, use or other dealings 51706f2543Smrgin this Software without prior written authorization from the X Consortium. 52706f2543Smrg */ 53706f2543Smrg 54706f2543Smrg/************************************************************ 55706f2543SmrgCopyright 1987 by Sun Microsystems, Inc. Mountain View, CA. 56706f2543Smrg 57706f2543Smrg All Rights Reserved 58706f2543Smrg 59706f2543SmrgPermission to use, copy, modify, and distribute this 60706f2543Smrgsoftware and its documentation for any purpose and without 61706f2543Smrgfee is hereby granted, provided that the above copyright no- 62706f2543Smrgtice appear in all copies and that both that copyright no- 63706f2543Smrgtice and this permission notice appear in supporting docu- 64706f2543Smrgmentation, and that the names of Sun or X Consortium 65ab290810Stsutsuinot be used in advertising or publicity pertaining to 66ab290810Stsutsuidistribution of the software without specific prior 67ab290810Stsutsuiwritten permission. Sun and X Consortium make no 68ab290810Stsutsuirepresentations about the suitability of this software for 69ab290810Stsutsuiany purpose. It is provided "as is" without any express or 70706f2543Smrgimplied warranty. 71706f2543Smrg 72706f2543SmrgSUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 73706f2543SmrgINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- 74706f2543SmrgNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI- 75706f2543SmrgABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 76706f2543SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 77706f2543SmrgPROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 78706f2543SmrgOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH 79706f2543SmrgTHE USE OR PERFORMANCE OF THIS SOFTWARE. 80706f2543Smrg 81706f2543Smrg********************************************************/ 82706f2543Smrg 83706f2543Smrg/* 84706f2543Smrg * Copyright (c) 1987 by the Regents of the University of California 85706f2543Smrg * Copyright (c) 1987 by Adam de Boor, UC Berkeley 86706f2543Smrg * 87706f2543Smrg * Permission to use, copy, modify, and distribute this 88706f2543Smrg * software and its documentation for any purpose and without 89706f2543Smrg * fee is hereby granted, provided that the above copyright 90706f2543Smrg * notice appear in all copies. The University of California 91706f2543Smrg * makes no representations about the suitability of this 92706f2543Smrg * software for any purpose. It is provided "as is" without 93706f2543Smrg * express or implied warranty. 94706f2543Smrg */ 95706f2543Smrg 96706f2543Smrg/****************************************************************/ 97706f2543Smrg/* Modified from sunCG4C.c for X11R3 by Tom Jarmolowski */ 98706f2543Smrg/****************************************************************/ 99706f2543Smrg 100ab290810Stsutsui/* 101706f2543Smrg * Copyright 1991, 1992, 1993 Kaleb S. Keithley 102706f2543Smrg * 103706f2543Smrg * Permission to use, copy, modify, and distribute this 104706f2543Smrg * software and its documentation for any purpose and without 105706f2543Smrg * fee is hereby granted, provided that the above copyright 106ab290810Stsutsui * notice appear in all copies. Kaleb S. Keithley makes no 107ab290810Stsutsui * representations about the suitability of this software for 108ab290810Stsutsui * any purpose. It is provided "as is" without express or 109706f2543Smrg * implied warranty. 110706f2543Smrg */ 111706f2543Smrg 112706f2543Smrg#include "x68k.h" 113706f2543Smrg#include "mi.h" 114706f2543Smrg#include "micmap.h" 115706f2543Smrg 116706f2543Smrg#include "fb.h" 117706f2543Smrg 118706f2543Smrg/* local functions */ 119706f2543Smrgstatic Bool x68kCfbFinishScreenInit(ScreenPtr pScreen, pointer pbits, 120706f2543Smrg int xsize, int ysize, 121706f2543Smrg int dpix, int dpiy, int width); 122706f2543Smrgstatic void x68kInstallColormap(ColormapPtr cmap); 123706f2543Smrgstatic void x68kUninstallColormap(ColormapPtr cmap); 124706f2543Smrgstatic int x68kListInstalledColormaps(ScreenPtr pScreen, Colormap *pCmapList); 125706f2543Smrgstatic void x68kStoreColors(ColormapPtr pmap, int ndef, xColorItem *pdefs); 126706f2543Smrg 127706f2543Smrgstatic void x68kUpdateColormap(ScreenPtr pScreen, int dex, int count, 12884d30d9dStsutsui uint8_t *rmap, uint8_t *gmap, uint8_t *bmap); 129706f2543Smrg 130706f2543Smrg/*------------------------------------------------------------------------- 131706f2543Smrg * function "x68kGraphOpen" [ X68kFBProc function ] 132706f2543Smrg * 133706f2543Smrg * purpose: call common frame buffer opening procedure 134ab290810Stsutsui * then set hardware colormap for several static color modes. 135706f2543Smrg * argument: (X68kScreenRec *)pPriv : X68k private screen record 136706f2543Smrg * returns: (Bool): TRUE if successed 137706f2543Smrg * FALSE otherwise 138706f2543Smrg *-----------------------------------------------------------------------*/ 139706f2543SmrgBool 140706f2543Smrgx68kGraphOpen(X68kScreenRec *pPriv) 141706f2543Smrg{ 142706f2543Smrg if( !x68kFbCommonOpen(pPriv, "/dev/grf1") ) 143706f2543Smrg return FALSE; 144706f2543Smrg 145706f2543Smrg /* initialize hardware colormap 146706f2543Smrg in cases of static visual class */ 147706f2543Smrg if (pPriv->depth == 15 && pPriv->class == TrueColor) { 148706f2543Smrg /* for 32768 TrueColor mode */ 149706f2543Smrg int i; 15084d30d9dStsutsui uint16_t x = 0x0001; 151706f2543Smrg for ( i = 0; i < 256; ) { 152706f2543Smrg pPriv->reg->gpal[i++] = x; 153706f2543Smrg pPriv->reg->gpal[i++] = x; 154ab290810Stsutsui x += 0x0202; 155706f2543Smrg } 156706f2543Smrg } 157706f2543Smrg if (pPriv->depth == 4 && pPriv->class == StaticGray ) { 158706f2543Smrg /* for 16 StaticGray mode */ 159706f2543Smrg int i; 160706f2543Smrg for( i = 0; i < 16; i++ ) 161706f2543Smrg pPriv->reg->gpal[i] = (i*2 << 11) | (i*2 << 6) | (i*2 << 1); 162706f2543Smrg } 163706f2543Smrg return TRUE; 164706f2543Smrg} 165706f2543Smrg 166706f2543Smrg/*------------------------------------------------------------------------- 167706f2543Smrg * function "x68kGraphClose" [ X68kFBProc function ] 168706f2543Smrg * 169706f2543Smrg * purpose: close graphic frame buffer 170706f2543Smrg * argument: (X68kScreenRec *)pPriv : X68k private screen record 171706f2543Smrg * returns: nothing 172706f2543Smrg *-----------------------------------------------------------------------*/ 173706f2543Smrgvoid 174706f2543Smrgx68kGraphClose(X68kScreenRec *pPriv) 175706f2543Smrg{ 176706f2543Smrg x68kFbCommonClose(pPriv); 177706f2543Smrg} 178706f2543Smrg 179706f2543Smrg/*------------------------------------------------------------------------- 180706f2543Smrg * function "x68kGraphInit" [ called by DIX AddScreen ] 181706f2543Smrg * 182706f2543Smrg * purpose: initialize graphic frame buffer 183706f2543Smrg * argument: (int)screen : screen index 184706f2543Smrg * (ScreenPtr)pScreen : DIX screen record 185706f2543Smrg * (int)argc, (char **)argv : standard C arguments 186706f2543Smrg * returns: (Bool) : TRUE if succeeded 187706f2543Smrg * FALSE otherwise 188706f2543Smrg *-----------------------------------------------------------------------*/ 189706f2543SmrgBool 190706f2543Smrgx68kGraphInit(int screen, ScreenPtr pScreen, int argc, char *argv[]) 191706f2543Smrg{ 192706f2543Smrg X68kScreenRec *pPriv; 193706f2543Smrg 194706f2543Smrg /* get private screen record set by X68KConfig */ 195706f2543Smrg pPriv = x68kGetScreenRecByType(X68K_FB_GRAPHIC); 196ab290810Stsutsui 197706f2543Smrg /* store private record into screen */ 198706f2543Smrg if (!dixRegisterPrivateKey(&x68kScreenPrivateKeyRec, PRIVATE_SCREEN, 0)) { 199706f2543Smrg Error("dixRegisterPrivateKey failed"); 200706f2543Smrg return FALSE; 201706f2543Smrg } 202706f2543Smrg x68kSetScreenPrivate(pScreen, pPriv); 203ab290810Stsutsui 204706f2543Smrg /* register normal cfb screen functions */ 205706f2543Smrg if (!fbSetupScreen(pScreen, pPriv->fb, 206706f2543Smrg pPriv->scr_width, pPriv->scr_height, 207706f2543Smrg pPriv->dpi, pPriv->dpi, pPriv->fb_width, 208706f2543Smrg pPriv->depth)) 209706f2543Smrg return FALSE; 210706f2543Smrg 211706f2543Smrg /* register colormap functions */ 212706f2543Smrg pScreen->InstallColormap = x68kInstallColormap; 213706f2543Smrg pScreen->UninstallColormap = x68kUninstallColormap; 214706f2543Smrg pScreen->ListInstalledColormaps = x68kListInstalledColormaps; 215706f2543Smrg pScreen->StoreColors = x68kStoreColors; 216ab290810Stsutsui 217706f2543Smrg /* visual initialization and etc.. */ 218706f2543Smrg if (!x68kCfbFinishScreenInit(pScreen, pPriv->fb, 219706f2543Smrg pPriv->scr_width, pPriv->scr_height, 220706f2543Smrg pPriv->dpi, pPriv->dpi, pPriv->fb_width)) 221706f2543Smrg return FALSE; 222706f2543Smrg 223706f2543Smrg if ( !miDCInitialize(pScreen, &x68kPointerScreenFuncs) ) 224706f2543Smrg return FALSE; 225706f2543Smrg 226706f2543Smrg pScreen->whitePixel = 1; 227706f2543Smrg pScreen->blackPixel = 0; 228706f2543Smrg if ( !miCreateDefColormap(pScreen) ) 229706f2543Smrg return FALSE; 230ab290810Stsutsui 231706f2543Smrg return TRUE; 232706f2543Smrg} 233706f2543Smrg 234706f2543Smrg/*------------------------------------------------------------------------- 235706f2543Smrg * function "x68kCfbFinishScreenInit" 236706f2543Smrg * 237706f2543Smrg * purpose: initialize visuals and perform miscellaneous settings 238706f2543Smrg * argument: (ScreenPtr)pScreen : DIX screen record 239706f2543Smrg * (pointer)pbits : frame buffer 240706f2543Smrg * (int)xsize, (int)ysize : screen size 241706f2543Smrg * (int)dpix, (int)dpiy : screen resolution in dots per inch 242706f2543Smrg * (int)width : pixel width of frame buffer 243706f2543Smrg * returns: (Bool) : TRUE if succeeded 244706f2543Smrg * FALSE otherwise 245706f2543Smrg *-----------------------------------------------------------------------*/ 246706f2543Smrgstatic Bool 247706f2543Smrgx68kCfbFinishScreenInit( 248706f2543Smrg ScreenPtr pScreen, 249706f2543Smrg pointer pbits, 250706f2543Smrg int xsize, int ysize, 251706f2543Smrg int dpix, int dpiy, 252706f2543Smrg int width) 253706f2543Smrg{ 254706f2543Smrg X68kScreenRec *pPriv = x68kGetScreenPrivate(pScreen); 255706f2543Smrg VisualPtr visuals; 256706f2543Smrg int nvisuals; 257706f2543Smrg DepthPtr depths; 258706f2543Smrg int ndepths; 259706f2543Smrg VisualID defaultVisual; 260706f2543Smrg int rootdepth = 0; 261706f2543Smrg 262706f2543Smrg /* for 15/16bit TrueColor visual mode */ 263706f2543Smrg if (pPriv->depth == 15 && pPriv->class == TrueColor) { 264706f2543Smrg VisualID *vid = NULL; 265706f2543Smrg 266706f2543Smrg ndepths = 1; 267706f2543Smrg nvisuals = 1; 26884d30d9dStsutsui depths = malloc( sizeof(DepthRec) ); 26984d30d9dStsutsui visuals = malloc( sizeof(VisualRec) ); 27084d30d9dStsutsui vid = malloc( sizeof(VisualID) ); 271706f2543Smrg if( !depths || !visuals || !vid ) { 272706f2543Smrg free( depths ); 273706f2543Smrg free( visuals ); 274706f2543Smrg free( vid ); 275706f2543Smrg return FALSE; 276706f2543Smrg } 277706f2543Smrg depths[0].depth = 15; 278706f2543Smrg depths[0].numVids = 1; 279706f2543Smrg depths[0].vids = vid; 280706f2543Smrg visuals[0].class = TrueColor; 281706f2543Smrg visuals[0].bitsPerRGBValue = 5; 282706f2543Smrg visuals[0].ColormapEntries = 1 << 5; 283706f2543Smrg visuals[0].nplanes = 15; 284706f2543Smrg visuals[0].vid = *vid = FakeClientID(0); 285706f2543Smrg visuals[0].greenMask = 0xf800; 286706f2543Smrg visuals[0].redMask = 0x07c0; 287706f2543Smrg visuals[0].blueMask = 0x003e; 288706f2543Smrg visuals[0].offsetGreen = 11; 289706f2543Smrg visuals[0].offsetRed = 6; 290706f2543Smrg visuals[0].offsetBlue = 1; 291706f2543Smrg rootdepth = 15; 292706f2543Smrg defaultVisual = *vid; 293706f2543Smrg } 294706f2543Smrg /* for 4/16bit StaticGray visual mode */ 295706f2543Smrg else if (pPriv->depth == 4 && pPriv->class == StaticGray ) { 296706f2543Smrg VisualID *vid = NULL; 297ab290810Stsutsui 298706f2543Smrg ndepths = 1; 299706f2543Smrg nvisuals = 1; 30084d30d9dStsutsui depths = malloc( sizeof(DepthRec) ); 30184d30d9dStsutsui visuals = malloc( sizeof(VisualRec) ); 30284d30d9dStsutsui vid = malloc( sizeof(VisualID) ); 303706f2543Smrg if( !depths || !visuals || !vid ) { 304706f2543Smrg free( depths ); 305706f2543Smrg free( visuals ); 306706f2543Smrg free( vid ); 307706f2543Smrg return FALSE; 308706f2543Smrg } 309706f2543Smrg depths[0].depth = 4; 310706f2543Smrg depths[0].numVids = 1; 311706f2543Smrg depths[0].vids = vid; 312706f2543Smrg visuals[0].class = StaticGray; 313706f2543Smrg visuals[0].bitsPerRGBValue = 4; 314706f2543Smrg visuals[0].ColormapEntries = 1 << 4; 315706f2543Smrg visuals[0].nplanes = 4; 316706f2543Smrg visuals[0].vid = *vid = FakeClientID(0); 317706f2543Smrg visuals[0].greenMask = 0; 318706f2543Smrg visuals[0].redMask = 0; 319706f2543Smrg visuals[0].blueMask = 0; 320706f2543Smrg visuals[0].offsetGreen = 0; 321706f2543Smrg visuals[0].offsetRed = 0; 322706f2543Smrg visuals[0].offsetBlue = 0; 323706f2543Smrg rootdepth = 4; 324706f2543Smrg defaultVisual = *vid; 325706f2543Smrg } 326706f2543Smrg /* for other modes ( supports all visuals ) */ 327706f2543Smrg else if (!miInitVisuals(&visuals, &depths, &nvisuals, &ndepths, 328706f2543Smrg &rootdepth, &defaultVisual, 1 << (16 - 1), 329706f2543Smrg 5, PseudoColor)) 330706f2543Smrg return FALSE; 331706f2543Smrg 332706f2543Smrg if (!miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width, 333706f2543Smrg rootdepth, ndepths, depths, 334706f2543Smrg defaultVisual, nvisuals, visuals)) 335706f2543Smrg return FALSE; 336ab290810Stsutsui 337706f2543Smrg pScreen->CloseScreen = fbCloseScreen; 338706f2543Smrg pScreen->SaveScreen = x68kSaveScreen; 339706f2543Smrg miInitializeBackingStore (pScreen); 340706f2543Smrg 341706f2543Smrg return TRUE; 342706f2543Smrg} 343706f2543Smrg 344706f2543Smrg/*------------------------------------------------------------------------- 345706f2543Smrg * function "x68kInstallColormap" [ screen function ] 346706f2543Smrg * 347706f2543Smrg * purpose: install colormap, then update hardware colormap. 348706f2543Smrg * argument: (ColormapPtr)cmap : colormap to install 349706f2543Smrg * returns: nothing 350706f2543Smrg *-----------------------------------------------------------------------*/ 351706f2543Smrgstatic void 352706f2543Smrgx68kInstallColormap(ColormapPtr cmap) 353706f2543Smrg{ 354706f2543Smrg X68kScreenRec *pPriv = x68kGetScreenPrivate(cmap->pScreen); 355706f2543Smrg register int i; 356706f2543Smrg register Entry *pent; 357706f2543Smrg register VisualPtr pVisual = cmap->pVisual; 35884d30d9dStsutsui uint8_t rmap[256], gmap[256], bmap[256]; 359706f2543Smrg unsigned long rMask, gMask, bMask; 360706f2543Smrg int oRed, oGreen, oBlue; 361706f2543Smrg 362706f2543Smrg if (cmap == pPriv->installedMap) 363706f2543Smrg return; 364706f2543Smrg if (pPriv->installedMap) 365706f2543Smrg WalkTree(pPriv->installedMap->pScreen, TellLostMap, 366706f2543Smrg (pointer) &(pPriv->installedMap->mid)); 367706f2543Smrg 368706f2543Smrg if (pPriv->class & DynamicClass) { 369706f2543Smrg if ((cmap->pVisual->class | DynamicClass) == DirectColor) { 370706f2543Smrg rMask = pVisual->redMask; 371706f2543Smrg gMask = pVisual->greenMask; 372706f2543Smrg bMask = pVisual->blueMask; 373706f2543Smrg oRed = pVisual->offsetRed; 374706f2543Smrg oGreen = pVisual->offsetGreen; 375706f2543Smrg oBlue = pVisual->offsetBlue; 376706f2543Smrg for (i = 0; i < 1<<(pPriv->depth); i++) { 377706f2543Smrg rmap[i] = cmap->red[(i & rMask) >> oRed].co.local.red >> 11; 378706f2543Smrg gmap[i] = cmap->green[(i & gMask) >> oGreen].co.local.green >> 11; 379706f2543Smrg bmap[i] = cmap->blue[(i & bMask) >> oBlue].co.local.blue >> 11; 380706f2543Smrg } 381706f2543Smrg } else { 382706f2543Smrg for (i = 0, pent = cmap->red; 383706f2543Smrg i < pVisual->ColormapEntries; 384706f2543Smrg i++, pent++) { 385706f2543Smrg if (pent->fShared) { 386706f2543Smrg rmap[i] = pent->co.shco.red->color >> 11; 387706f2543Smrg gmap[i] = pent->co.shco.green->color >> 11; 388706f2543Smrg bmap[i] = pent->co.shco.blue->color >> 11; 389706f2543Smrg } 390706f2543Smrg else { 391706f2543Smrg rmap[i] = pent->co.local.red >> 11; 392706f2543Smrg gmap[i] = pent->co.local.green >> 11; 393706f2543Smrg bmap[i] = pent->co.local.blue >> 11; 394706f2543Smrg } 395706f2543Smrg } 396706f2543Smrg } 397706f2543Smrg x68kUpdateColormap(cmap->pScreen, 0, 1<<(pPriv->depth), rmap, gmap, bmap); 398706f2543Smrg } 399706f2543Smrg pPriv->installedMap = cmap; 400706f2543Smrg WalkTree(cmap->pScreen, TellGainedMap, (pointer) &(cmap->mid)); 401706f2543Smrg} 402706f2543Smrg 403706f2543Smrg/*------------------------------------------------------------------------- 404706f2543Smrg * function "x68kUninstallColormap" [ screen function ] 405706f2543Smrg * 406706f2543Smrg * purpose: uninstall colormap 407706f2543Smrg * argument: (ColormapPtr)cmap : colormap to uninstall 408706f2543Smrg * returns: nothing 409706f2543Smrg *-----------------------------------------------------------------------*/ 410706f2543Smrgstatic void 411706f2543Smrgx68kUninstallColormap(ColormapPtr cmap) 412706f2543Smrg{ 413706f2543Smrg X68kScreenRec *pPriv = x68kGetScreenPrivate(cmap->pScreen); 414706f2543Smrg 415706f2543Smrg if (cmap == pPriv->installedMap) { 416706f2543Smrg Colormap defMapID = cmap->pScreen->defColormap; 417706f2543Smrg 418706f2543Smrg if (cmap->mid != defMapID) { 419706f2543Smrg ColormapPtr defMap = (ColormapPtr) LookupIDByType(defMapID, 420706f2543Smrg RT_COLORMAP); 421706f2543Smrg (*cmap->pScreen->InstallColormap)(defMap); 422706f2543Smrg } 423706f2543Smrg } 424706f2543Smrg} 425706f2543Smrg 426706f2543Smrg/*------------------------------------------------------------------------- 427706f2543Smrg * function "x68kListInstalledColormaps" [ screen function ] 428706f2543Smrg * 429706f2543Smrg * purpose: Get the list of currently installed colormaps. 430706f2543Smrg * In X68k, installed colormap in always only one. 431706f2543Smrg * argument: (ScreenPtr)pScreen : screen 432706f2543Smrg * (Colormap *)pCmapList : colormap list got 433706f2543Smrg * returns: (int) 434706f2543Smrg *-----------------------------------------------------------------------*/ 435706f2543Smrgstatic int 436706f2543Smrgx68kListInstalledColormaps(ScreenPtr pScreen, Colormap *pCmapList) 437706f2543Smrg{ 438706f2543Smrg X68kScreenRec *pPriv = x68kGetScreenPrivate(pScreen); 439706f2543Smrg *pCmapList = pPriv->installedMap->mid; 440706f2543Smrg return 1; 441706f2543Smrg} 442706f2543Smrg 443706f2543Smrg/*------------------------------------------------------------------------- 444706f2543Smrg * function "x68kStoreColors" [ screen function ] 445706f2543Smrg * 446706f2543Smrg * purpose: store specified color items 447706f2543Smrg * argument: (ColormapPtr)pmap : colormap 448706f2543Smrg * (int)ndef : the number of items 449706f2543Smrg * (xColorItem *)pdefs : items 450706f2543Smrg * returns: nothing 451706f2543Smrg *-----------------------------------------------------------------------*/ 452706f2543Smrgstatic void 453706f2543Smrgx68kStoreColors(ColormapPtr pmap, int ndef, xColorItem *pdefs) 454706f2543Smrg{ 455706f2543Smrg X68kScreenRec *pPriv = x68kGetScreenPrivate(pmap->pScreen); 45684d30d9dStsutsui uint8_t rmap[256], gmap[256], bmap[256]; 457706f2543Smrg xColorItem expanddefs[256]; 458706f2543Smrg register int i; 459706f2543Smrg 460706f2543Smrg if (pPriv->installedMap != NULL && pPriv->installedMap != pmap) 461706f2543Smrg return; 462706f2543Smrg if ((pmap->pVisual->class | DynamicClass) == DirectColor) { 463706f2543Smrg ndef = fbExpandDirectColors(pmap, ndef, pdefs, expanddefs); 464706f2543Smrg pdefs = expanddefs; 465706f2543Smrg } 466706f2543Smrg while (ndef--) { 467706f2543Smrg i = pdefs->pixel; 468706f2543Smrg rmap[i] = pdefs->red >> 11; 469706f2543Smrg gmap[i] = pdefs->green >> 11; 470706f2543Smrg bmap[i] = pdefs->blue >> 11; 471706f2543Smrg x68kUpdateColormap(pmap->pScreen, i, 1, rmap, gmap, bmap); 472706f2543Smrg pdefs++; 473706f2543Smrg } 474706f2543Smrg} 475706f2543Smrg 476706f2543Smrg/*------------------------------------------------------------------------- 477706f2543Smrg * function "x68kUpdateColormap" 478706f2543Smrg * 479706f2543Smrg * purpose: update hardware colormap 480706f2543Smrg * argument: (ScreenPtr)pScreen: screen 481706f2543Smrg * (int)dex : colormap index 482706f2543Smrg * (int)count : count for updating 48384d30d9dStsutsui * (uint8_t *)[rgb]map: each map 484706f2543Smrg * returns: nothing 485706f2543Smrg *-----------------------------------------------------------------------*/ 486706f2543Smrgstatic void 487706f2543Smrgx68kUpdateColormap(ScreenPtr pScreen, int dex, int count, 48884d30d9dStsutsui uint8_t *rmap, uint8_t *gmap, uint8_t *bmap) 489706f2543Smrg{ 490706f2543Smrg X68kScreenRec *pPriv = x68kGetScreenPrivate(pScreen); 49184d30d9dStsutsui volatile uint16_t *pal = pPriv->reg->gpal; 492706f2543Smrg 493706f2543Smrg for( ; count > 0; count--,dex++ ) { 49484d30d9dStsutsui pal[dex] = (uint16_t)gmap[dex] << 11 | 49584d30d9dStsutsui (uint16_t)rmap[dex] << 6 | 49684d30d9dStsutsui (uint16_t)bmap[dex] << 1; 497706f2543Smrg } 498706f2543Smrg} 499706f2543Smrg 500706f2543Smrg/* EOF x68kGraph.c */ 501