|
|
1.1 ! root 1: /*- ! 2: * sunBW2.c -- ! 3: * Functions for handling the sun BWTWO board. ! 4: * ! 5: * Copyright (c) 1987 by the Regents of the University of California ! 6: * Copyright (c) 1987 by Adam de Boor, UC Berkeley ! 7: * ! 8: * Permission to use, copy, modify, and distribute this ! 9: * software and its documentation for any purpose and without ! 10: * fee is hereby granted, provided that the above copyright ! 11: * notice appear in all copies. The University of California ! 12: * makes no representations about the suitability of this ! 13: * software for any purpose. It is provided "as is" without ! 14: * express or implied warranty. ! 15: * ! 16: * ! 17: */ ! 18: ! 19: /************************************************************ ! 20: Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA. ! 21: ! 22: All Rights Reserved ! 23: ! 24: Permission to use, copy, modify, and distribute this ! 25: software and its documentation for any purpose and without ! 26: fee is hereby granted, provided that the above copyright no- ! 27: tice appear in all copies and that both that copyright no- ! 28: tice and this permission notice appear in supporting docu- ! 29: mentation, and that the names of Sun or MIT not be used in ! 30: advertising or publicity pertaining to distribution of the ! 31: software without specific prior written permission. Sun and ! 32: M.I.T. make no representations about the suitability of this ! 33: software for any purpose. It is provided "as is" without any ! 34: express or implied warranty. ! 35: ! 36: SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, ! 37: INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- ! 38: NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI- ! 39: ABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ! 40: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR ! 41: PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR ! 42: OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH ! 43: THE USE OR PERFORMANCE OF THIS SOFTWARE. ! 44: ! 45: ********************************************************/ ! 46: ! 47: ! 48: /*- ! 49: * Copyright (c) 1987 by Sun Microsystems, Inc. ! 50: */ ! 51: ! 52: #include "sun.h" ! 53: #include "resource.h" ! 54: ! 55: #include <sys/mman.h> ! 56: ! 57: /*- ! 58: *----------------------------------------------------------------------- ! 59: * sunBW2SaveScreen -- ! 60: * Disable the video on the frame buffer to save the screen. ! 61: * ! 62: * Results: ! 63: * None. ! 64: * ! 65: * Side Effects: ! 66: * Video enable state changes. ! 67: * ! 68: *----------------------------------------------------------------------- ! 69: */ ! 70: static Bool ! 71: sunBW2SaveScreen (pScreen, on) ! 72: ScreenPtr pScreen; ! 73: Bool on; ! 74: { ! 75: int state = on; ! 76: ! 77: switch (on) { ! 78: case SCREEN_SAVER_FORCER: ! 79: SetTimeSinceLastInputEvent(); ! 80: screenSaved = FALSE; ! 81: /* ! 82: state = FBVIDEO_ON; ! 83: */ ! 84: break; ! 85: case SCREEN_SAVER_OFF: ! 86: screenSaved = FALSE; ! 87: /* ! 88: state = FBVIDEO_ON; ! 89: */ ! 90: break; ! 91: case SCREEN_SAVER_ON: ! 92: default: ! 93: screenSaved = TRUE; ! 94: /* ! 95: state = FBVIDEO_OFF; ! 96: */ ! 97: break; ! 98: } ! 99: /* ! 100: (void) ioctl(sunFbs[pScreen->myNum].fd, FBIOSVIDEO, &state); ! 101: */ ! 102: return TRUE; ! 103: } ! 104: ! 105: /*- ! 106: *----------------------------------------------------------------------- ! 107: * sunBW2CloseScreen -- ! 108: * called to ensure video is enabled when server exits. ! 109: * ! 110: * Results: ! 111: * Screen is unsaved. ! 112: * ! 113: * Side Effects: ! 114: * None ! 115: * ! 116: *----------------------------------------------------------------------- ! 117: */ ! 118: /*ARGSUSED*/ ! 119: static Bool ! 120: sunBW2CloseScreen(i, pScreen) ! 121: int i; ! 122: ScreenPtr pScreen; ! 123: { ! 124: return (pScreen->SaveScreen(pScreen, SCREEN_SAVER_OFF)); ! 125: } ! 126: ! 127: /*- ! 128: *----------------------------------------------------------------------- ! 129: * sunBW2ResolveColor -- ! 130: * Resolve an RGB value into some sort of thing we can handle. ! 131: * Just looks to see if the intensity of the color is greater than ! 132: * 1/2 and sets it to 'white' (all ones) if so and 'black' (all zeroes) ! 133: * if not. ! 134: * ! 135: * Results: ! 136: * *pred, *pgreen and *pblue are overwritten with the resolved color. ! 137: * ! 138: * Side Effects: ! 139: * see above. ! 140: * ! 141: *----------------------------------------------------------------------- ! 142: */ ! 143: /*ARGSUSED*/ ! 144: static void ! 145: sunBW2ResolveColor(pred, pgreen, pblue, pVisual) ! 146: unsigned short *pred; ! 147: unsigned short *pgreen; ! 148: unsigned short *pblue; ! 149: VisualPtr pVisual; ! 150: { ! 151: /* ! 152: * Gets intensity from RGB. If intensity is >= half, pick white, else ! 153: * pick black. This may well be more trouble than it's worth. ! 154: */ ! 155: *pred = *pgreen = *pblue = ! 156: (((39L * *pred + ! 157: 50L * *pgreen + ! 158: 11L * *pblue) >> 8) >= (((1<<8)-1)*50)) ? ~0 : 0; ! 159: } ! 160: ! 161: /*- ! 162: *----------------------------------------------------------------------- ! 163: * sunBW2CreateColormap -- ! 164: * create a bw colormap ! 165: * ! 166: * Results: ! 167: * None ! 168: * ! 169: * Side Effects: ! 170: * allocate two pixels ! 171: * ! 172: *----------------------------------------------------------------------- ! 173: */ ! 174: void ! 175: sunBW2CreateColormap(pmap) ! 176: ColormapPtr pmap; ! 177: { ! 178: int red, green, blue, pix; ! 179: ! 180: /* this is a monochrome colormap, it only has two entries, just fill ! 181: * them in by hand. If it were a more complex static map, it would be ! 182: * worth writing a for loop or three to initialize it */ ! 183: ! 184: /* this will be pixel 0 */ ! 185: red = green = blue = ~0; ! 186: AllocColor(pmap, &red, &green, &blue, &pix, 0); ! 187: ! 188: /* this will be pixel 1 */ ! 189: red = green = blue = 0; ! 190: AllocColor(pmap, &red, &green, &blue, &pix, 0); ! 191: ! 192: } ! 193: ! 194: /*- ! 195: *----------------------------------------------------------------------- ! 196: * sunBW2DestroyColormap -- ! 197: * destroy a bw colormap ! 198: * ! 199: * Results: ! 200: * None ! 201: * ! 202: * Side Effects: ! 203: * None ! 204: * ! 205: *----------------------------------------------------------------------- ! 206: */ ! 207: /*ARGSUSED*/ ! 208: void ! 209: sunBW2DestroyColormap(pmap) ! 210: ColormapPtr pmap; ! 211: { ! 212: } ! 213: ! 214: /*- ! 215: *----------------------------------------------------------------------- ! 216: * sunBW2Init -- ! 217: * Attempt to find and initialize a bw2 framebuffer ! 218: * ! 219: * Results: ! 220: * None ! 221: * ! 222: * Side Effects: ! 223: * Most of the elements of the ScreenRec are filled in. The ! 224: * video is enabled for the frame buffer... ! 225: * ! 226: *----------------------------------------------------------------------- ! 227: */ ! 228: /*ARGSUSED*/ ! 229: static Bool ! 230: sunBW2Init (index, pScreen, argc, argv) ! 231: int index; /* The index of pScreen in the ScreenInfo */ ! 232: ScreenPtr pScreen; /* The Screen to initialize */ ! 233: int argc; /* The number of the Server's arguments. */ ! 234: char **argv; /* The arguments themselves. Don't change! */ ! 235: { ! 236: ColormapPtr pColormap; ! 237: ! 238: if (!mfbScreenInit(index, pScreen, ! 239: sunFbs[index].fb, ! 240: sunFbs[index].info.fb_width, ! 241: sunFbs[index].info.fb_height, 90, 90)) ! 242: return (FALSE); ! 243: ! 244: pScreen->SaveScreen = sunBW2SaveScreen; ! 245: pScreen->RealizeCursor = sunRealizeCursor; ! 246: pScreen->UnrealizeCursor = sunUnrealizeCursor; ! 247: pScreen->DisplayCursor = sunDisplayCursor; ! 248: pScreen->SetCursorPosition = sunSetCursorPosition; ! 249: pScreen->CursorLimits = sunCursorLimits; ! 250: pScreen->PointerNonInterestBox = sunPointerNonInterestBox; ! 251: pScreen->ConstrainCursor = sunConstrainCursor; ! 252: pScreen->RecolorCursor = sunRecolorCursor; ! 253: pScreen->ResolveColor = sunBW2ResolveColor; ! 254: pScreen->CreateColormap = sunBW2CreateColormap; ! 255: pScreen->DestroyColormap = sunBW2DestroyColormap; ! 256: pScreen->RegionCreate = miRegionCreate; ! 257: pScreen->RegionCopy = miRegionCopy; ! 258: pScreen->RegionDestroy = miRegionDestroy; ! 259: pScreen->Intersect = miIntersect; ! 260: pScreen->Inverse = miInverse; ! 261: pScreen->Union = miUnion; ! 262: pScreen->Subtract = miSubtract; ! 263: pScreen->RegionReset = miRegionReset; ! 264: pScreen->TranslateRegion = miTranslateRegion; ! 265: pScreen->RectIn = miRectIn; ! 266: pScreen->PointInRegion = miPointInRegion; ! 267: pScreen->whitePixel = 0; ! 268: pScreen->blackPixel = 1; ! 269: ! 270: if (CreateColormap(pScreen->defColormap, pScreen, ! 271: LookupID(pScreen->rootVisual, RT_VISUALID, RC_CORE), ! 272: &pColormap, AllocNone, 0) != Success ! 273: || pColormap == NULL) ! 274: FatalError("Can't create colormap in sunBW2Init()\n"); ! 275: mfbInstallColormap(pColormap); ! 276: ! 277: /* ! 278: * Enable video output...? ! 279: */ ! 280: (void) sunBW2SaveScreen(pScreen, SCREEN_SAVER_FORCER); ! 281: ! 282: sunScreenInit(pScreen); ! 283: return (TRUE); ! 284: ! 285: } ! 286: ! 287: /*- ! 288: *----------------------------------------------------------------------- ! 289: * sunBW2Probe -- ! 290: * Attempt to find and initialize a bw2 framebuffer ! 291: * ! 292: * Results: ! 293: * None ! 294: * ! 295: * Side Effects: ! 296: * Memory is allocated for the frame buffer and the buffer is mapped. ! 297: * ! 298: *----------------------------------------------------------------------- ! 299: */ ! 300: ! 301: Bool ! 302: sunBW2Probe(pScreenInfo, index, fbNum, argc, argv) ! 303: ScreenInfo *pScreenInfo; /* The screenInfo struct */ ! 304: int index; /* The index of pScreen in the ScreenInfo */ ! 305: int fbNum; /* Index into the sunFbData array */ ! 306: int argc; /* The number of the Server's arguments. */ ! 307: char **argv; /* The arguments themselves. Don't change! */ ! 308: { ! 309: int i, oldNumScreens; ! 310: ! 311: if (sunFbData[fbNum].probeStatus == probedAndFailed) { ! 312: return FALSE; ! 313: } ! 314: ! 315: if (sunFbData[fbNum].probeStatus == neverProbed) { ! 316: int fd; ! 317: struct fbtype fbType; ! 318: char *bitmap = (char *)NULL; ! 319: char *valloc(); ! 320: ! 321: if ((fd = sunOpenFrameBuffer(FBTYPE_SUN2BW, &fbType, index, fbNum, ! 322: argc, argv)) < 0) { ! 323: sunFbData[fbNum].probeStatus = probedAndFailed; ! 324: return FALSE; ! 325: } ! 326: ! 327: bitmap = valloc(fbType.fb_size); ! 328: if (bitmap == (char *) NULL) { ! 329: ErrorF("Could not allocate room for frame buffer.\n"); ! 330: sunFbData[fbNum].probeStatus = probedAndFailed; ! 331: (void) close(fd); ! 332: return FALSE; ! 333: } ! 334: if (mmap(bitmap, fbType.fb_size, PROT_READ|PROT_WRITE, fd, 0) < 0) { ! 335: ErrorF("Mapping bw2"); ! 336: sunFbData[fbNum].probeStatus = probedAndFailed; ! 337: (void) close(fd); ! 338: return FALSE; ! 339: } ! 340: ! 341: sunFbs[index].fb = (pointer) bitmap; ! 342: sunFbs[index].fd = fd; ! 343: sunFbs[index].info = fbType; ! 344: sunFbs[index].EnterLeave = NoopDDA; ! 345: sunFbData[fbNum].probeStatus = probedAndSucceeded; ! 346: ! 347: } ! 348: ! 349: /* ! 350: * If we've ever successfully probed this device, do the following. ! 351: */ ! 352: oldNumScreens = pScreenInfo->numScreens; ! 353: i = AddScreen(sunBW2Init, argc, argv); ! 354: pScreenInfo->screen[index].CloseScreen = sunBW2CloseScreen; ! 355: return (i > oldNumScreens); ! 356: } ! 357:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.