19c576acfStsutsui/* $NetBSD: x68kGraph.c,v 1.10 2021/03/11 12:08:57 tsutsui Exp $ */ 2ba64b02eStsutsui/*------------------------------------------------------------------------- 3ba64b02eStsutsui * Copyright (c) 1996 Yasushi Yamasaki 4ba64b02eStsutsui * All rights reserved. 5ba64b02eStsutsui * 6ba64b02eStsutsui * Redistribution and use in source and binary forms, with or without 7ba64b02eStsutsui * modification, are permitted provided that the following conditions 8ba64b02eStsutsui * are met: 9ba64b02eStsutsui * 1. Redistributions of source code must retain the above copyright 10ba64b02eStsutsui * notice, this list of conditions and the following disclaimer. 11ba64b02eStsutsui * 2. Redistributions in binary form must reproduce the above copyright 12ba64b02eStsutsui * notice, this list of conditions and the following disclaimer in the 13ba64b02eStsutsui * documentation and/or other materials provided with the distribution. 14ba64b02eStsutsui * 15ba64b02eStsutsui * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16ba64b02eStsutsui * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17ba64b02eStsutsui * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18ba64b02eStsutsui * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19ba64b02eStsutsui * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20ba64b02eStsutsui * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21ba64b02eStsutsui * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22ba64b02eStsutsui * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23ba64b02eStsutsui * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24ba64b02eStsutsui * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25ba64b02eStsutsui *-----------------------------------------------------------------------*/ 26ba64b02eStsutsui 27ba64b02eStsutsui/* $XConsortium: sunCfb.c,v 1.15.1.2 95/01/12 18:54:42 kaleb Exp $ */ 28ba64b02eStsutsui 29ba64b02eStsutsui/* 30ba64b02eStsutsuiCopyright (c) 1990 X Consortium 31ba64b02eStsutsui 32ba64b02eStsutsuiPermission is hereby granted, free of charge, to any person obtaining a copy 33ba64b02eStsutsuiof this software and associated documentation files (the "Software"), to deal 34ba64b02eStsutsuiin the Software without restriction, including without limitation the rights 35ba64b02eStsutsuito use, copy, modify, merge, publish, distribute, sublicense, and/or sell 36ba64b02eStsutsuicopies of the Software, and to permit persons to whom the Software is 37ba64b02eStsutsuifurnished to do so, subject to the following conditions: 38ba64b02eStsutsui 39ba64b02eStsutsuiThe above copyright notice and this permission notice shall be included in 40ba64b02eStsutsuiall copies or substantial portions of the Software. 41ba64b02eStsutsui 42ba64b02eStsutsuiTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 43ba64b02eStsutsuiIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 44ba64b02eStsutsuiFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 45ba64b02eStsutsuiX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 46ba64b02eStsutsuiAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 47ba64b02eStsutsuiCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 48ba64b02eStsutsui 49ba64b02eStsutsuiExcept as contained in this notice, the name of the X Consortium shall not be 50ba64b02eStsutsuiused in advertising or otherwise to promote the sale, use or other dealings 51ba64b02eStsutsuiin this Software without prior written authorization from the X Consortium. 52ba64b02eStsutsui */ 53ba64b02eStsutsui 54ba64b02eStsutsui/************************************************************ 55ba64b02eStsutsuiCopyright 1987 by Sun Microsystems, Inc. Mountain View, CA. 56ba64b02eStsutsui 57ba64b02eStsutsui All Rights Reserved 58ba64b02eStsutsui 59ba64b02eStsutsuiPermission to use, copy, modify, and distribute this 60ba64b02eStsutsuisoftware and its documentation for any purpose and without 61ba64b02eStsutsuifee is hereby granted, provided that the above copyright no- 62ba64b02eStsutsuitice appear in all copies and that both that copyright no- 63ba64b02eStsutsuitice and this permission notice appear in supporting docu- 64ba64b02eStsutsuimentation, 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 70ba64b02eStsutsuiimplied warranty. 71ba64b02eStsutsui 72ba64b02eStsutsuiSUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 73ba64b02eStsutsuiINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- 74ba64b02eStsutsuiNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI- 75ba64b02eStsutsuiABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 76ba64b02eStsutsuiANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 77ba64b02eStsutsuiPROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 78ba64b02eStsutsuiOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH 79ba64b02eStsutsuiTHE USE OR PERFORMANCE OF THIS SOFTWARE. 80ba64b02eStsutsui 81ba64b02eStsutsui********************************************************/ 82ba64b02eStsutsui 83ba64b02eStsutsui/* 84ba64b02eStsutsui * Copyright (c) 1987 by the Regents of the University of California 85ba64b02eStsutsui * Copyright (c) 1987 by Adam de Boor, UC Berkeley 86ba64b02eStsutsui * 87ba64b02eStsutsui * Permission to use, copy, modify, and distribute this 88ba64b02eStsutsui * software and its documentation for any purpose and without 89ba64b02eStsutsui * fee is hereby granted, provided that the above copyright 90ba64b02eStsutsui * notice appear in all copies. The University of California 91ba64b02eStsutsui * makes no representations about the suitability of this 92ba64b02eStsutsui * software for any purpose. It is provided "as is" without 93ba64b02eStsutsui * express or implied warranty. 94ba64b02eStsutsui */ 95ba64b02eStsutsui 96ba64b02eStsutsui/****************************************************************/ 97ba64b02eStsutsui/* Modified from sunCG4C.c for X11R3 by Tom Jarmolowski */ 98ba64b02eStsutsui/****************************************************************/ 99ba64b02eStsutsui 100ab290810Stsutsui/* 101ba64b02eStsutsui * Copyright 1991, 1992, 1993 Kaleb S. Keithley 102ba64b02eStsutsui * 103ba64b02eStsutsui * Permission to use, copy, modify, and distribute this 104ba64b02eStsutsui * software and its documentation for any purpose and without 105ba64b02eStsutsui * 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 109ba64b02eStsutsui * implied warranty. 110ba64b02eStsutsui */ 111ba64b02eStsutsui 112ba64b02eStsutsui#include "x68k.h" 113ba64b02eStsutsui#include "mi.h" 114ba64b02eStsutsui#include "micmap.h" 115ba64b02eStsutsui 116ba64b02eStsutsui#include "fb.h" 117ba64b02eStsutsui 118ba64b02eStsutsui/* local functions */ 1195ca846b1Stsutsuistatic Bool x68kCfbFinishScreenInit(ScreenPtr pScreen, void *pbits, 120ba64b02eStsutsui int xsize, int ysize, 121ba64b02eStsutsui int dpix, int dpiy, int width); 122ba64b02eStsutsuistatic void x68kInstallColormap(ColormapPtr cmap); 123ba64b02eStsutsuistatic void x68kUninstallColormap(ColormapPtr cmap); 124ba64b02eStsutsuistatic int x68kListInstalledColormaps(ScreenPtr pScreen, Colormap *pCmapList); 125ba64b02eStsutsuistatic void x68kStoreColors(ColormapPtr pmap, int ndef, xColorItem *pdefs); 126ba64b02eStsutsui 127ba64b02eStsutsuistatic void x68kUpdateColormap(ScreenPtr pScreen, int dex, int count, 1289b65525fStsutsui uint8_t *rmap, uint8_t *gmap, uint8_t *bmap); 129ba64b02eStsutsui 130ba64b02eStsutsui/*------------------------------------------------------------------------- 131ba64b02eStsutsui * function "x68kGraphOpen" [ X68kFBProc function ] 132ba64b02eStsutsui * 133ba64b02eStsutsui * purpose: call common frame buffer opening procedure 134ab290810Stsutsui * then set hardware colormap for several static color modes. 135ba64b02eStsutsui * argument: (X68kScreenRec *)pPriv : X68k private screen record 136ba64b02eStsutsui * returns: (Bool): TRUE if successed 137ba64b02eStsutsui * FALSE otherwise 138ba64b02eStsutsui *-----------------------------------------------------------------------*/ 139ba64b02eStsutsuiBool 140ba64b02eStsutsuix68kGraphOpen(X68kScreenRec *pPriv) 141ba64b02eStsutsui{ 142ba64b02eStsutsui if( !x68kFbCommonOpen(pPriv, "/dev/grf1") ) 143ba64b02eStsutsui return FALSE; 144ba64b02eStsutsui 145ba64b02eStsutsui /* initialize hardware colormap 146ba64b02eStsutsui in cases of static visual class */ 147ba64b02eStsutsui if (pPriv->depth == 15 && pPriv->class == TrueColor) { 148ba64b02eStsutsui /* for 32768 TrueColor mode */ 149ba64b02eStsutsui int i; 1509b65525fStsutsui uint16_t x = 0x0001; 151ba64b02eStsutsui for ( i = 0; i < 256; ) { 152ba64b02eStsutsui pPriv->reg->gpal[i++] = x; 153ba64b02eStsutsui pPriv->reg->gpal[i++] = x; 154ab290810Stsutsui x += 0x0202; 155ba64b02eStsutsui } 156ba64b02eStsutsui } 157ba64b02eStsutsui if (pPriv->depth == 4 && pPriv->class == StaticGray ) { 158ba64b02eStsutsui /* for 16 StaticGray mode */ 159ba64b02eStsutsui int i; 160ba64b02eStsutsui for( i = 0; i < 16; i++ ) 161ba64b02eStsutsui pPriv->reg->gpal[i] = (i*2 << 11) | (i*2 << 6) | (i*2 << 1); 162ba64b02eStsutsui } 163ba64b02eStsutsui return TRUE; 164ba64b02eStsutsui} 165ba64b02eStsutsui 166ba64b02eStsutsui/*------------------------------------------------------------------------- 167ba64b02eStsutsui * function "x68kGraphClose" [ X68kFBProc function ] 168ba64b02eStsutsui * 169ba64b02eStsutsui * purpose: close graphic frame buffer 170ba64b02eStsutsui * argument: (X68kScreenRec *)pPriv : X68k private screen record 171ba64b02eStsutsui * returns: nothing 172ba64b02eStsutsui *-----------------------------------------------------------------------*/ 173ba64b02eStsutsuivoid 174ba64b02eStsutsuix68kGraphClose(X68kScreenRec *pPriv) 175ba64b02eStsutsui{ 176ba64b02eStsutsui x68kFbCommonClose(pPriv); 177ba64b02eStsutsui} 178ba64b02eStsutsui 179ba64b02eStsutsui/*------------------------------------------------------------------------- 180ba64b02eStsutsui * function "x68kGraphInit" [ called by DIX AddScreen ] 181ba64b02eStsutsui * 182ba64b02eStsutsui * purpose: initialize graphic frame buffer 183909daefdSmrg * argument: (ScreenPtr)pScreen : DIX screen record 184ba64b02eStsutsui * (int)argc, (char **)argv : standard C arguments 185ba64b02eStsutsui * returns: (Bool) : TRUE if succeeded 186ba64b02eStsutsui * FALSE otherwise 187ba64b02eStsutsui *-----------------------------------------------------------------------*/ 188ba64b02eStsutsuiBool 189909daefdSmrgx68kGraphInit(ScreenPtr pScreen, int argc, char *argv[]) 190ba64b02eStsutsui{ 191ba64b02eStsutsui X68kScreenRec *pPriv; 192ba64b02eStsutsui 193ba64b02eStsutsui /* get private screen record set by X68KConfig */ 194ba64b02eStsutsui pPriv = x68kGetScreenRecByType(X68K_FB_GRAPHIC); 195ab290810Stsutsui 196ba64b02eStsutsui /* store private record into screen */ 197ba64b02eStsutsui if (!dixRegisterPrivateKey(&x68kScreenPrivateKeyRec, PRIVATE_SCREEN, 0)) { 1989c576acfStsutsui ErrorF("dixRegisterPrivateKey failed\n"); 199ba64b02eStsutsui return FALSE; 200ba64b02eStsutsui } 201ba64b02eStsutsui x68kSetScreenPrivate(pScreen, pPriv); 202ab290810Stsutsui 203ba64b02eStsutsui /* register normal cfb screen functions */ 204ba64b02eStsutsui if (!fbSetupScreen(pScreen, pPriv->fb, 205ba64b02eStsutsui pPriv->scr_width, pPriv->scr_height, 206ba64b02eStsutsui pPriv->dpi, pPriv->dpi, pPriv->fb_width, 207ba64b02eStsutsui pPriv->depth)) 208ba64b02eStsutsui return FALSE; 209ba64b02eStsutsui 210ba64b02eStsutsui /* register colormap functions */ 211ba64b02eStsutsui pScreen->InstallColormap = x68kInstallColormap; 212ba64b02eStsutsui pScreen->UninstallColormap = x68kUninstallColormap; 213ba64b02eStsutsui pScreen->ListInstalledColormaps = x68kListInstalledColormaps; 214ba64b02eStsutsui pScreen->StoreColors = x68kStoreColors; 215ab290810Stsutsui 216ba64b02eStsutsui /* visual initialization and etc.. */ 217ba64b02eStsutsui if (!x68kCfbFinishScreenInit(pScreen, pPriv->fb, 218ba64b02eStsutsui pPriv->scr_width, pPriv->scr_height, 219ba64b02eStsutsui pPriv->dpi, pPriv->dpi, pPriv->fb_width)) 220ba64b02eStsutsui return FALSE; 221ba64b02eStsutsui 222ba64b02eStsutsui if ( !miDCInitialize(pScreen, &x68kPointerScreenFuncs) ) 223ba64b02eStsutsui return FALSE; 224ba64b02eStsutsui 225ba64b02eStsutsui pScreen->whitePixel = 1; 226ba64b02eStsutsui pScreen->blackPixel = 0; 227ba64b02eStsutsui if ( !miCreateDefColormap(pScreen) ) 228ba64b02eStsutsui return FALSE; 229ab290810Stsutsui 230ba64b02eStsutsui return TRUE; 231ba64b02eStsutsui} 232ba64b02eStsutsui 233ba64b02eStsutsui/*------------------------------------------------------------------------- 234ba64b02eStsutsui * function "x68kCfbFinishScreenInit" 235ba64b02eStsutsui * 236ba64b02eStsutsui * purpose: initialize visuals and perform miscellaneous settings 237ba64b02eStsutsui * argument: (ScreenPtr)pScreen : DIX screen record 2385ca846b1Stsutsui * (void *)pbits : frame buffer 239ba64b02eStsutsui * (int)xsize, (int)ysize : screen size 240ba64b02eStsutsui * (int)dpix, (int)dpiy : screen resolution in dots per inch 241ba64b02eStsutsui * (int)width : pixel width of frame buffer 242ba64b02eStsutsui * returns: (Bool) : TRUE if succeeded 243ba64b02eStsutsui * FALSE otherwise 244ba64b02eStsutsui *-----------------------------------------------------------------------*/ 245ba64b02eStsutsuistatic Bool 246ba64b02eStsutsuix68kCfbFinishScreenInit( 247ba64b02eStsutsui ScreenPtr pScreen, 2485ca846b1Stsutsui void *pbits, 249ba64b02eStsutsui int xsize, int ysize, 250ba64b02eStsutsui int dpix, int dpiy, 251ba64b02eStsutsui int width) 252ba64b02eStsutsui{ 253ba64b02eStsutsui X68kScreenRec *pPriv = x68kGetScreenPrivate(pScreen); 254ba64b02eStsutsui VisualPtr visuals; 255ba64b02eStsutsui int nvisuals; 256ba64b02eStsutsui DepthPtr depths; 257ba64b02eStsutsui int ndepths; 258ba64b02eStsutsui VisualID defaultVisual; 259ba64b02eStsutsui int rootdepth = 0; 260ba64b02eStsutsui 261ba64b02eStsutsui /* for 15/16bit TrueColor visual mode */ 262ba64b02eStsutsui if (pPriv->depth == 15 && pPriv->class == TrueColor) { 263ba64b02eStsutsui VisualID *vid = NULL; 264ba64b02eStsutsui 265ba64b02eStsutsui ndepths = 1; 266ba64b02eStsutsui nvisuals = 1; 267d998ab55Stsutsui depths = malloc( sizeof(DepthRec) ); 268d998ab55Stsutsui visuals = malloc( sizeof(VisualRec) ); 269d998ab55Stsutsui vid = malloc( sizeof(VisualID) ); 270ba64b02eStsutsui if( !depths || !visuals || !vid ) { 271a2ab6c90Stsutsui free( depths ); 272a2ab6c90Stsutsui free( visuals ); 273a2ab6c90Stsutsui free( vid ); 274ba64b02eStsutsui return FALSE; 275ba64b02eStsutsui } 276ba64b02eStsutsui depths[0].depth = 15; 277ba64b02eStsutsui depths[0].numVids = 1; 278ba64b02eStsutsui depths[0].vids = vid; 279ba64b02eStsutsui visuals[0].class = TrueColor; 280ba64b02eStsutsui visuals[0].bitsPerRGBValue = 5; 281ba64b02eStsutsui visuals[0].ColormapEntries = 1 << 5; 282ba64b02eStsutsui visuals[0].nplanes = 15; 283ba64b02eStsutsui visuals[0].vid = *vid = FakeClientID(0); 284ba64b02eStsutsui visuals[0].greenMask = 0xf800; 285ba64b02eStsutsui visuals[0].redMask = 0x07c0; 286ba64b02eStsutsui visuals[0].blueMask = 0x003e; 287ba64b02eStsutsui visuals[0].offsetGreen = 11; 288ba64b02eStsutsui visuals[0].offsetRed = 6; 289ba64b02eStsutsui visuals[0].offsetBlue = 1; 290ba64b02eStsutsui rootdepth = 15; 291ba64b02eStsutsui defaultVisual = *vid; 292ba64b02eStsutsui } 293ba64b02eStsutsui /* for 4/16bit StaticGray visual mode */ 294ba64b02eStsutsui else if (pPriv->depth == 4 && pPriv->class == StaticGray ) { 295ba64b02eStsutsui VisualID *vid = NULL; 296ab290810Stsutsui 297ba64b02eStsutsui ndepths = 1; 298ba64b02eStsutsui nvisuals = 1; 299d998ab55Stsutsui depths = malloc( sizeof(DepthRec) ); 300d998ab55Stsutsui visuals = malloc( sizeof(VisualRec) ); 301d998ab55Stsutsui vid = malloc( sizeof(VisualID) ); 302ba64b02eStsutsui if( !depths || !visuals || !vid ) { 303a2ab6c90Stsutsui free( depths ); 304a2ab6c90Stsutsui free( visuals ); 305a2ab6c90Stsutsui free( vid ); 306ba64b02eStsutsui return FALSE; 307ba64b02eStsutsui } 308ba64b02eStsutsui depths[0].depth = 4; 309ba64b02eStsutsui depths[0].numVids = 1; 310ba64b02eStsutsui depths[0].vids = vid; 311ba64b02eStsutsui visuals[0].class = StaticGray; 312ba64b02eStsutsui visuals[0].bitsPerRGBValue = 4; 313ba64b02eStsutsui visuals[0].ColormapEntries = 1 << 4; 314ba64b02eStsutsui visuals[0].nplanes = 4; 315ba64b02eStsutsui visuals[0].vid = *vid = FakeClientID(0); 316ba64b02eStsutsui visuals[0].greenMask = 0; 317ba64b02eStsutsui visuals[0].redMask = 0; 318ba64b02eStsutsui visuals[0].blueMask = 0; 319ba64b02eStsutsui visuals[0].offsetGreen = 0; 320ba64b02eStsutsui visuals[0].offsetRed = 0; 321ba64b02eStsutsui visuals[0].offsetBlue = 0; 322ba64b02eStsutsui rootdepth = 4; 323ba64b02eStsutsui defaultVisual = *vid; 324ba64b02eStsutsui } 325ba64b02eStsutsui /* for other modes ( supports all visuals ) */ 326ba64b02eStsutsui else if (!miInitVisuals(&visuals, &depths, &nvisuals, &ndepths, 327ba64b02eStsutsui &rootdepth, &defaultVisual, 1 << (16 - 1), 328ba64b02eStsutsui 5, PseudoColor)) 329ba64b02eStsutsui return FALSE; 330ba64b02eStsutsui 331ba64b02eStsutsui if (!miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width, 332ba64b02eStsutsui rootdepth, ndepths, depths, 333ba64b02eStsutsui defaultVisual, nvisuals, visuals)) 334ba64b02eStsutsui return FALSE; 335ab290810Stsutsui 336ba64b02eStsutsui pScreen->CloseScreen = fbCloseScreen; 337ba64b02eStsutsui pScreen->SaveScreen = x68kSaveScreen; 338ba64b02eStsutsui 339ba64b02eStsutsui return TRUE; 340ba64b02eStsutsui} 341ba64b02eStsutsui 342ba64b02eStsutsui/*------------------------------------------------------------------------- 343ba64b02eStsutsui * function "x68kInstallColormap" [ screen function ] 344ba64b02eStsutsui * 345ba64b02eStsutsui * purpose: install colormap, then update hardware colormap. 346ba64b02eStsutsui * argument: (ColormapPtr)cmap : colormap to install 347ba64b02eStsutsui * returns: nothing 348ba64b02eStsutsui *-----------------------------------------------------------------------*/ 349ba64b02eStsutsuistatic void 350ba64b02eStsutsuix68kInstallColormap(ColormapPtr cmap) 351ba64b02eStsutsui{ 352ba64b02eStsutsui X68kScreenRec *pPriv = x68kGetScreenPrivate(cmap->pScreen); 353ba64b02eStsutsui register int i; 354ba64b02eStsutsui register Entry *pent; 355ba64b02eStsutsui register VisualPtr pVisual = cmap->pVisual; 3569b65525fStsutsui uint8_t rmap[256], gmap[256], bmap[256]; 357ba64b02eStsutsui unsigned long rMask, gMask, bMask; 358ba64b02eStsutsui int oRed, oGreen, oBlue; 359ba64b02eStsutsui 360ba64b02eStsutsui if (cmap == pPriv->installedMap) 361ba64b02eStsutsui return; 362ba64b02eStsutsui if (pPriv->installedMap) 363ba64b02eStsutsui WalkTree(pPriv->installedMap->pScreen, TellLostMap, 3645ca846b1Stsutsui (void *) &(pPriv->installedMap->mid)); 365ba64b02eStsutsui 366ba64b02eStsutsui if (pPriv->class & DynamicClass) { 367ba64b02eStsutsui if ((cmap->pVisual->class | DynamicClass) == DirectColor) { 368ba64b02eStsutsui rMask = pVisual->redMask; 369ba64b02eStsutsui gMask = pVisual->greenMask; 370ba64b02eStsutsui bMask = pVisual->blueMask; 371ba64b02eStsutsui oRed = pVisual->offsetRed; 372ba64b02eStsutsui oGreen = pVisual->offsetGreen; 373ba64b02eStsutsui oBlue = pVisual->offsetBlue; 374ba64b02eStsutsui for (i = 0; i < 1<<(pPriv->depth); i++) { 375ba64b02eStsutsui rmap[i] = cmap->red[(i & rMask) >> oRed].co.local.red >> 11; 376ba64b02eStsutsui gmap[i] = cmap->green[(i & gMask) >> oGreen].co.local.green >> 11; 377ba64b02eStsutsui bmap[i] = cmap->blue[(i & bMask) >> oBlue].co.local.blue >> 11; 378ba64b02eStsutsui } 379ba64b02eStsutsui } else { 380ba64b02eStsutsui for (i = 0, pent = cmap->red; 381ba64b02eStsutsui i < pVisual->ColormapEntries; 382ba64b02eStsutsui i++, pent++) { 383ba64b02eStsutsui if (pent->fShared) { 384ba64b02eStsutsui rmap[i] = pent->co.shco.red->color >> 11; 385ba64b02eStsutsui gmap[i] = pent->co.shco.green->color >> 11; 386ba64b02eStsutsui bmap[i] = pent->co.shco.blue->color >> 11; 387ba64b02eStsutsui } 388ba64b02eStsutsui else { 389ba64b02eStsutsui rmap[i] = pent->co.local.red >> 11; 390ba64b02eStsutsui gmap[i] = pent->co.local.green >> 11; 391ba64b02eStsutsui bmap[i] = pent->co.local.blue >> 11; 392ba64b02eStsutsui } 393ba64b02eStsutsui } 394ba64b02eStsutsui } 395ba64b02eStsutsui x68kUpdateColormap(cmap->pScreen, 0, 1<<(pPriv->depth), rmap, gmap, bmap); 396ba64b02eStsutsui } 397ba64b02eStsutsui pPriv->installedMap = cmap; 3985ca846b1Stsutsui WalkTree(cmap->pScreen, TellGainedMap, (void *) &(cmap->mid)); 399ba64b02eStsutsui} 400ba64b02eStsutsui 401ba64b02eStsutsui/*------------------------------------------------------------------------- 402ba64b02eStsutsui * function "x68kUninstallColormap" [ screen function ] 403ba64b02eStsutsui * 404ba64b02eStsutsui * purpose: uninstall colormap 405ba64b02eStsutsui * argument: (ColormapPtr)cmap : colormap to uninstall 406ba64b02eStsutsui * returns: nothing 407ba64b02eStsutsui *-----------------------------------------------------------------------*/ 408ba64b02eStsutsuistatic void 409ba64b02eStsutsuix68kUninstallColormap(ColormapPtr cmap) 410ba64b02eStsutsui{ 411ba64b02eStsutsui X68kScreenRec *pPriv = x68kGetScreenPrivate(cmap->pScreen); 412ba64b02eStsutsui 413ba64b02eStsutsui if (cmap == pPriv->installedMap) { 414ba64b02eStsutsui Colormap defMapID = cmap->pScreen->defColormap; 415ba64b02eStsutsui 416ba64b02eStsutsui if (cmap->mid != defMapID) { 4175ca846b1Stsutsui void *retval; 418909daefdSmrg ColormapPtr defMap; 419909daefdSmrg dixLookupResourceByType(&retval, defMapID, RT_COLORMAP, 420909daefdSmrg serverClient, DixReadAccess); 421909daefdSmrg defMap = (ColormapPtr) retval; 422ba64b02eStsutsui (*cmap->pScreen->InstallColormap)(defMap); 423ba64b02eStsutsui } 424ba64b02eStsutsui } 425ba64b02eStsutsui} 426ba64b02eStsutsui 427ba64b02eStsutsui/*------------------------------------------------------------------------- 428ba64b02eStsutsui * function "x68kListInstalledColormaps" [ screen function ] 429ba64b02eStsutsui * 430ba64b02eStsutsui * purpose: Get the list of currently installed colormaps. 431ba64b02eStsutsui * In X68k, installed colormap in always only one. 432ba64b02eStsutsui * argument: (ScreenPtr)pScreen : screen 433ba64b02eStsutsui * (Colormap *)pCmapList : colormap list got 434ba64b02eStsutsui * returns: (int) 435ba64b02eStsutsui *-----------------------------------------------------------------------*/ 436ba64b02eStsutsuistatic int 437ba64b02eStsutsuix68kListInstalledColormaps(ScreenPtr pScreen, Colormap *pCmapList) 438ba64b02eStsutsui{ 439ba64b02eStsutsui X68kScreenRec *pPriv = x68kGetScreenPrivate(pScreen); 440ba64b02eStsutsui *pCmapList = pPriv->installedMap->mid; 441ba64b02eStsutsui return 1; 442ba64b02eStsutsui} 443ba64b02eStsutsui 444ba64b02eStsutsui/*------------------------------------------------------------------------- 445ba64b02eStsutsui * function "x68kStoreColors" [ screen function ] 446ba64b02eStsutsui * 447ba64b02eStsutsui * purpose: store specified color items 448ba64b02eStsutsui * argument: (ColormapPtr)pmap : colormap 449ba64b02eStsutsui * (int)ndef : the number of items 450ba64b02eStsutsui * (xColorItem *)pdefs : items 451ba64b02eStsutsui * returns: nothing 452ba64b02eStsutsui *-----------------------------------------------------------------------*/ 453ba64b02eStsutsuistatic void 454ba64b02eStsutsuix68kStoreColors(ColormapPtr pmap, int ndef, xColorItem *pdefs) 455ba64b02eStsutsui{ 456ba64b02eStsutsui X68kScreenRec *pPriv = x68kGetScreenPrivate(pmap->pScreen); 4579b65525fStsutsui uint8_t rmap[256], gmap[256], bmap[256]; 458ba64b02eStsutsui xColorItem expanddefs[256]; 459ba64b02eStsutsui register int i; 460ba64b02eStsutsui 461ba64b02eStsutsui if (pPriv->installedMap != NULL && pPriv->installedMap != pmap) 462ba64b02eStsutsui return; 463ba64b02eStsutsui if ((pmap->pVisual->class | DynamicClass) == DirectColor) { 464ba64b02eStsutsui ndef = fbExpandDirectColors(pmap, ndef, pdefs, expanddefs); 465ba64b02eStsutsui pdefs = expanddefs; 466ba64b02eStsutsui } 467ba64b02eStsutsui while (ndef--) { 468ba64b02eStsutsui i = pdefs->pixel; 469ba64b02eStsutsui rmap[i] = pdefs->red >> 11; 470ba64b02eStsutsui gmap[i] = pdefs->green >> 11; 471ba64b02eStsutsui bmap[i] = pdefs->blue >> 11; 472ba64b02eStsutsui x68kUpdateColormap(pmap->pScreen, i, 1, rmap, gmap, bmap); 473ba64b02eStsutsui pdefs++; 474ba64b02eStsutsui } 475ba64b02eStsutsui} 476ba64b02eStsutsui 477ba64b02eStsutsui/*------------------------------------------------------------------------- 478ba64b02eStsutsui * function "x68kUpdateColormap" 479ba64b02eStsutsui * 480ba64b02eStsutsui * purpose: update hardware colormap 481ba64b02eStsutsui * argument: (ScreenPtr)pScreen: screen 482ba64b02eStsutsui * (int)dex : colormap index 483ba64b02eStsutsui * (int)count : count for updating 4849b65525fStsutsui * (uint8_t *)[rgb]map: each map 485ba64b02eStsutsui * returns: nothing 486ba64b02eStsutsui *-----------------------------------------------------------------------*/ 487ba64b02eStsutsuistatic void 488ba64b02eStsutsuix68kUpdateColormap(ScreenPtr pScreen, int dex, int count, 4899b65525fStsutsui uint8_t *rmap, uint8_t *gmap, uint8_t *bmap) 490ba64b02eStsutsui{ 491ba64b02eStsutsui X68kScreenRec *pPriv = x68kGetScreenPrivate(pScreen); 4929b65525fStsutsui volatile uint16_t *pal = pPriv->reg->gpal; 493ba64b02eStsutsui 494ba64b02eStsutsui for( ; count > 0; count--,dex++ ) { 4959b65525fStsutsui pal[dex] = (uint16_t)gmap[dex] << 11 | 4969b65525fStsutsui (uint16_t)rmap[dex] << 6 | 4979b65525fStsutsui (uint16_t)bmap[dex] << 1; 498ba64b02eStsutsui } 499ba64b02eStsutsui} 500ba64b02eStsutsui 501ba64b02eStsutsui/* EOF x68kGraph.c */ 502