|
|
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: #ifndef lint
49: static char sccsid[] = "%W %G Copyright 1987 Sun Micro";
50: #endif
51:
52: /*-
53: * Copyright (c) 1987 by Sun Microsystems, Inc.
54: */
55:
56: #include "sun.h"
57: #include "resource.h"
58:
59: #include <sys/mman.h>
60: #include <sundev/bw2reg.h>
61:
62: extern caddr_t mmap();
63:
64: typedef struct bw2 {
65: u_char image[BW2_FBSIZE]; /* Pixel buffer */
66: } BW2, BW2Rec, *BW2Ptr;
67:
68: typedef struct bw2hr {
69: u_char image[BW2_FBSIZE_HIRES]; /* Pixel buffer */
70: } BW2HR, BW2HRRec, *BW2HRPtr;
71:
72:
73: /*-
74: *-----------------------------------------------------------------------
75: * sunBW2SaveScreen --
76: * Disable the video on the frame buffer to save the screen.
77: *
78: * Results:
79: * None.
80: *
81: * Side Effects:
82: * Video enable state changes.
83: *
84: *-----------------------------------------------------------------------
85: */
86: static Bool
87: sunBW2SaveScreen (pScreen, on)
88: ScreenPtr pScreen;
89: Bool on;
90: {
91: int state = on;
92:
93: switch (on) {
94: case SCREEN_SAVER_FORCER:
95: SetTimeSinceLastInputEvent();
96: screenSaved = FALSE;
97: state = FBVIDEO_ON;
98: break;
99: case SCREEN_SAVER_OFF:
100: screenSaved = FALSE;
101: state = FBVIDEO_ON;
102: break;
103: case SCREEN_SAVER_ON:
104: default:
105: screenSaved = TRUE;
106: state = FBVIDEO_OFF;
107: break;
108: }
109: (void) ioctl(sunFbs[pScreen->myNum].fd, FBIOSVIDEO, &state);
110: return TRUE;
111: }
112:
113: /*-
114: *-----------------------------------------------------------------------
115: * sunBW2CloseScreen --
116: * called to ensure video is enabled when server exits.
117: *
118: * Results:
119: * Screen is unsaved.
120: *
121: * Side Effects:
122: * None
123: *
124: *-----------------------------------------------------------------------
125: */
126: /*ARGSUSED*/
127: static Bool
128: sunBW2CloseScreen(i, pScreen)
129: int i;
130: ScreenPtr pScreen;
131: {
132: return (pScreen->SaveScreen(pScreen, SCREEN_SAVER_OFF));
133: }
134:
135: /*-
136: *-----------------------------------------------------------------------
137: * sunBW2ResolveColor --
138: * Resolve an RGB value into some sort of thing we can handle.
139: * Just looks to see if the intensity of the color is greater than
140: * 1/2 and sets it to 'white' (all ones) if so and 'black' (all zeroes)
141: * if not.
142: *
143: * Results:
144: * *pred, *pgreen and *pblue are overwritten with the resolved color.
145: *
146: * Side Effects:
147: * see above.
148: *
149: *-----------------------------------------------------------------------
150: */
151: /*ARGSUSED*/
152: static void
153: sunBW2ResolveColor(pred, pgreen, pblue, pVisual)
154: unsigned short *pred;
155: unsigned short *pgreen;
156: unsigned short *pblue;
157: VisualPtr pVisual;
158: {
159: /*
160: * Gets intensity from RGB. If intensity is >= half, pick white, else
161: * pick black. This may well be more trouble than it's worth.
162: */
163: *pred = *pgreen = *pblue =
164: (((39L * *pred +
165: 50L * *pgreen +
166: 11L * *pblue) >> 8) >= (((1<<8)-1)*50)) ? ~0 : 0;
167: }
168:
169: /*-
170: *-----------------------------------------------------------------------
171: * sunBW2CreateColormap --
172: * create a bw colormap
173: *
174: * Results:
175: * None
176: *
177: * Side Effects:
178: * allocate two pixels
179: *
180: *-----------------------------------------------------------------------
181: */
182: void
183: sunBW2CreateColormap(pmap)
184: ColormapPtr pmap;
185: {
186: int red, green, blue, pix;
187:
188: /* this is a monochrome colormap, it only has two entries, just fill
189: * them in by hand. If it were a more complex static map, it would be
190: * worth writing a for loop or three to initialize it */
191:
192: /* this will be pixel 0 */
193: red = green = blue = ~0;
194: AllocColor(pmap, &red, &green, &blue, &pix, 0);
195:
196: /* this will be pixel 1 */
197: red = green = blue = 0;
198: AllocColor(pmap, &red, &green, &blue, &pix, 0);
199:
200: }
201:
202: /*-
203: *-----------------------------------------------------------------------
204: * sunBW2DestroyColormap --
205: * destroy a bw colormap
206: *
207: * Results:
208: * None
209: *
210: * Side Effects:
211: * None
212: *
213: *-----------------------------------------------------------------------
214: */
215: /*ARGSUSED*/
216: void
217: sunBW2DestroyColormap(pmap)
218: ColormapPtr pmap;
219: {
220: }
221:
222: /*-
223: *-----------------------------------------------------------------------
224: * sunBW2Init --
225: * Attempt to find and initialize a bw2 framebuffer
226: *
227: * Results:
228: * None
229: *
230: * Side Effects:
231: * Most of the elements of the ScreenRec are filled in. The
232: * video is enabled for the frame buffer...
233: *
234: *-----------------------------------------------------------------------
235: */
236: /*ARGSUSED*/
237: static Bool
238: sunBW2Init (index, pScreen, argc, argv)
239: int index; /* The index of pScreen in the ScreenInfo */
240: ScreenPtr pScreen; /* The Screen to initialize */
241: int argc; /* The number of the Server's arguments. */
242: char **argv; /* The arguments themselves. Don't change! */
243: {
244: ColormapPtr pColormap;
245:
246: if (!mfbScreenInit(index, pScreen,
247: sunFbs[index].fb,
248: sunFbs[index].info.fb_width,
249: sunFbs[index].info.fb_height, 90, 90))
250: return (FALSE);
251:
252: pScreen->SaveScreen = sunBW2SaveScreen;
253: pScreen->RealizeCursor = sunRealizeCursor;
254: pScreen->UnrealizeCursor = sunUnrealizeCursor;
255: pScreen->DisplayCursor = sunDisplayCursor;
256: pScreen->SetCursorPosition = sunSetCursorPosition;
257: pScreen->CursorLimits = sunCursorLimits;
258: pScreen->PointerNonInterestBox = sunPointerNonInterestBox;
259: pScreen->ConstrainCursor = sunConstrainCursor;
260: pScreen->RecolorCursor = sunRecolorCursor;
261: pScreen->ResolveColor = sunBW2ResolveColor;
262: pScreen->CreateColormap = sunBW2CreateColormap;
263: pScreen->DestroyColormap = sunBW2DestroyColormap;
264: pScreen->RegionCreate = miRegionCreate;
265: pScreen->RegionCopy = miRegionCopy;
266: pScreen->RegionDestroy = miRegionDestroy;
267: pScreen->Intersect = miIntersect;
268: pScreen->Inverse = miInverse;
269: pScreen->Union = miUnion;
270: pScreen->Subtract = miSubtract;
271: pScreen->RegionReset = miRegionReset;
272: pScreen->TranslateRegion = miTranslateRegion;
273: pScreen->RectIn = miRectIn;
274: pScreen->PointInRegion = miPointInRegion;
275: pScreen->whitePixel = 0;
276: pScreen->blackPixel = 1;
277:
278: /*
279: * ZOIDS should only ever be defined if SUN_WINDOWS is also defined.
280: */
281: #ifdef ZOIDS
282: {
283: GCPtr pGC = CreateScratchGC(pScreen, 1);
284:
285: if (pGC) {
286: RegisterProc("PolySolidXAlignedTrapezoid", pGC,
287: sunBW2SolidXZoids);
288: RegisterProc("PolySolidYAlignedTrapezoid", pGC,
289: sunBW2SolidYZoids);
290: RegisterProc("PolyTiledXAlignedTrapezoid", pGC,
291: sunBW2TiledXZoids);
292: RegisterProc("PolyTiledYAlignedTrapezoid", pGC,
293: sunBW2TiledYZoids);
294: RegisterProc("PolyStipXAlignedTrapezoid", pGC,
295: sunBW2StipXZoids);
296: RegisterProc("PolyStipYAlignedTrapezoid", pGC,
297: sunBW2StipYZoids);
298: FreeScratchGC(pGC);
299: }
300: }
301: #endif ZOIDS
302:
303: if (CreateColormap(pScreen->defColormap, pScreen,
304: LookupID(pScreen->rootVisual, RT_VISUALID, RC_CORE),
305: &pColormap, AllocNone, 0) != Success
306: || pColormap == NULL)
307: FatalError("Can't create colormap in sunBW2Init()\n");
308: mfbInstallColormap(pColormap);
309:
310: /*
311: * Enable video output...?
312: */
313: (void) sunBW2SaveScreen(pScreen, SCREEN_SAVER_FORCER);
314:
315: sunScreenInit(pScreen);
316: return (TRUE);
317:
318: }
319:
320: /*-
321: *-----------------------------------------------------------------------
322: * sunBW2Probe --
323: * Attempt to find and initialize a bw2 framebuffer
324: *
325: * Results:
326: * None
327: *
328: * Side Effects:
329: * Memory is allocated for the frame buffer and the buffer is mapped.
330: *
331: *-----------------------------------------------------------------------
332: */
333:
334: Bool
335: sunBW2Probe(pScreenInfo, index, fbNum, argc, argv)
336: ScreenInfo *pScreenInfo; /* The screenInfo struct */
337: int index; /* The index of pScreen in the ScreenInfo */
338: int fbNum; /* Index into the sunFbData array */
339: int argc; /* The number of the Server's arguments. */
340: char **argv; /* The arguments themselves. Don't change! */
341: {
342: int i, oldNumScreens;
343:
344: if (sunFbData[fbNum].probeStatus == probedAndFailed) {
345: return FALSE;
346: }
347:
348: if (sunFbData[fbNum].probeStatus == neverProbed) {
349: int fd;
350: struct fbtype fbType;
351: BW2Ptr BW2fb = NULL; /* Place to map the thing */
352: BW2HRPtr BW2HRfb = NULL; /* Place to map the thing */
353: int isHiRes = 0;
354:
355: if ((fd = sunOpenFrameBuffer(FBTYPE_SUN2BW, &fbType, index, fbNum,
356: argc, argv)) < 0) {
357: sunFbData[fbNum].probeStatus = probedAndFailed;
358: return FALSE;
359: }
360:
361: isHiRes = (fbType.fb_width > 1152);
362: #ifdef _MAP_NEW
363: if (isHiRes) {
364: BW2HRfb = (BW2HRPtr) mmap((caddr_t) 0, sizeof(BW2HRRec),
365: PROT_READ | PROT_WRITE,
366: MAP_SHARED | _MAP_NEW,
367: fd, (off_t) 0);
368: if ((int)BW2HRfb == -1) {
369: Error("mapping BW2 (hires)");
370: sunFbData[fbNum].probeStatus = probedAndFailed;
371: (void) close(fd);
372: return FALSE;
373: }
374: }
375: else {
376: BW2fb = (BW2Ptr) mmap((caddr_t) 0, sizeof(BW2Rec),
377: PROT_READ | PROT_WRITE,
378: MAP_SHARED | _MAP_NEW,
379: fd, (off_t) 0);
380: if ((int)BW2fb == -1) {
381: Error("mapping BW2");
382: sunFbData[fbNum].probeStatus = probedAndFailed;
383: (void) close(fd);
384: return FALSE;
385: }
386: }
387: #else
388: if (isHiRes) {
389: BW2HRfb = (BW2HRPtr) valloc(sizeof(BW2HRRec));
390: }
391: else {
392: BW2fb = (BW2Ptr) valloc(sizeof(BW2Rec));
393: }
394: if ((BW2fb == (BW2Ptr) NULL) && (BW2HRfb == (BW2HRPtr) NULL)) {
395: ErrorF("Could not allocate room for frame buffer.\n");
396: sunFbData[fbNum].probeStatus = probedAndFailed;
397: (void) close(fd);
398: return FALSE;
399: }
400: if (mmap((isHiRes ? (pointer) BW2HRfb : (pointer) BW2fb),
401: (isHiRes ? sizeof(BW2HRRec) : sizeof(BW2Rec)),
402: PROT_READ | PROT_WRITE, MAP_SHARED,
403: fd, (off_t) 0) < 0) {
404: ErrorF("Mapping bw2");
405: sunFbData[fbNum].probeStatus = probedAndFailed;
406: (void) close(fd);
407: return FALSE;
408: }
409: #endif _MAP_NEW
410:
411: /*
412: * ZOIDS should only ever be defined if SUN_WINDOWS is also
413: * defined.
414: */
415: #ifdef ZOIDS
416: if ((sunFbData[fbNum].pr = pr_open(sunFbData[fbNum].devName)) == 0) {
417: ErrorF("Opening bw2 pixrect");
418: sunFbData[fbNum].probeStatus = probedAndFailed;
419: /* do we need to free BW2fb or BW2HRfb? */
420: (void) close(fd);
421: return FALSE;
422: }
423:
424: if ((sunFbData[fbNum].scratch_pr = mem_create(
425: fbType.fb_width, fbType.fb_height, 1)) == 0) {
426: ErrorF("Opening bw2 scratch pixrect");
427: sunFbData[fbNum].probeStatus = probedAndFailed;
428: /* do we need to free BW2fb or BW2HRfb? */
429: pr_destroy(sunFbData[fbNum].pr);
430: (void) close(fd);
431: return FALSE;
432: }
433: #endif ZOIDS
434: sunFbs[index].fb = (isHiRes ? (pointer) BW2HRfb : (pointer) BW2fb);
435: sunFbs[index].fd = fd;
436: sunFbs[index].info = fbType;
437: sunFbs[index].EnterLeave = NoopDDA;
438: sunFbData[fbNum].probeStatus = probedAndSucceeded;
439:
440: }
441:
442: /*
443: * If we've ever successfully probed this device, do the following.
444: */
445: oldNumScreens = pScreenInfo->numScreens;
446: i = AddScreen(sunBW2Init, argc, argv);
447: pScreenInfo->screen[index].CloseScreen = sunBW2CloseScreen;
448: return (i > oldNumScreens);
449: }
450:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.