pnozz_cursor.c revision a6b33934
1a6b33934Smacallan/*
2a6b33934Smacallan * SBus Weitek P9100 hardware cursor support
3a6b33934Smacallan *
4a6b33934Smacallan * Copyright (C) 2005 Michael Lorenz
5a6b33934Smacallan *
6a6b33934Smacallan * Permission is hereby granted, free of charge, to any person obtaining a copy
7a6b33934Smacallan * of this software and associated documentation files (the "Software"), to deal
8a6b33934Smacallan * in the Software without restriction, including without limitation the rights
9a6b33934Smacallan * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10a6b33934Smacallan * copies of the Software, and to permit persons to whom the Software is
11a6b33934Smacallan * furnished to do so, subject to the following conditions:
12a6b33934Smacallan *
13a6b33934Smacallan * The above copyright notice and this permission notice shall be included in
14a6b33934Smacallan * all copies or substantial portions of the Software.
15a6b33934Smacallan *
16a6b33934Smacallan * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17a6b33934Smacallan * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18a6b33934Smacallan * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19a6b33934Smacallan * MICHAEL LORENZ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20a6b33934Smacallan * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21a6b33934Smacallan * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22a6b33934Smacallan */
23a6b33934Smacallan/* $NetBSD: pnozz_cursor.c,v 1.1 2009/08/26 22:28:26 macallan Exp $ */
24a6b33934Smacallan
25a6b33934Smacallan#include <fcntl.h>
26a6b33934Smacallan#include <sys/time.h>
27a6b33934Smacallan#include <sys/types.h>
28a6b33934Smacallan#include <dev/sun/fbio.h>
29a6b33934Smacallan#include <dev/wscons/wsconsio.h>
30a6b33934Smacallan
31a6b33934Smacallan#include "pnozz.h"
32a6b33934Smacallan
33a6b33934Smacallanstatic void PnozzLoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src);
34a6b33934Smacallanstatic void PnozzSetCursorPosition(ScrnInfoPtr pScrn, int x, int y);
35a6b33934Smacallanstatic void PnozzSetCursorColors(ScrnInfoPtr pScrn, int bg, int fg);
36a6b33934Smacallan
37a6b33934Smacallanstatic void
38a6b33934SmacallanPnozzLoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src)
39a6b33934Smacallan{
40a6b33934Smacallan    PnozzPtr pPnozz = GET_PNOZZ_FROM_SCRN(pScrn);
41a6b33934Smacallan
42a6b33934Smacallan    pPnozz->Cursor.set = FB_CUR_SETSHAPE;
43a6b33934Smacallan    pPnozz->Cursor.image = src;
44a6b33934Smacallan    pPnozz->Cursor.mask = src + 0x200;
45a6b33934Smacallan
46a6b33934Smacallan    if (ioctl(pPnozz->psdp->fd, FBIOSCURSOR, &pPnozz->Cursor) == -1)
47a6b33934Smacallan	xf86Msg(X_ERROR, "FB_CUR_SETSHAPE failed\n");
48a6b33934Smacallan}
49a6b33934Smacallan
50a6b33934Smacallanvoid
51a6b33934SmacallanPnozzShowCursor(ScrnInfoPtr pScrn)
52a6b33934Smacallan{
53a6b33934Smacallan    PnozzPtr pPnozz = GET_PNOZZ_FROM_SCRN(pScrn);
54a6b33934Smacallan
55a6b33934Smacallan    if (pPnozz->Cursor.enable == 0) {
56a6b33934Smacallan    	pPnozz->Cursor.enable = 1;
57a6b33934Smacallan	pPnozz->Cursor.set = FB_CUR_SETCUR;
58a6b33934Smacallan	if (ioctl(pPnozz->psdp->fd, FBIOSCURSOR, &pPnozz->Cursor) == -1)
59a6b33934Smacallan	    xf86Msg(X_ERROR, "FB_CUR_SETCUR failed\n");
60a6b33934Smacallan    }
61a6b33934Smacallan}
62a6b33934Smacallan
63a6b33934Smacallanvoid
64a6b33934SmacallanPnozzHideCursor(ScrnInfoPtr pScrn)
65a6b33934Smacallan{
66a6b33934Smacallan    PnozzPtr pPnozz = GET_PNOZZ_FROM_SCRN(pScrn);
67a6b33934Smacallan
68a6b33934Smacallan    if (pPnozz->Cursor.enable == 1) {
69a6b33934Smacallan    	pPnozz->Cursor.enable = 0;
70a6b33934Smacallan	pPnozz->Cursor.set = FB_CUR_SETCUR;
71a6b33934Smacallan	if (ioctl(pPnozz->psdp->fd, FBIOSCURSOR, &pPnozz->Cursor) == -1)
72a6b33934Smacallan	    xf86Msg(X_ERROR, "FB_CUR_SETCUR failed\n");
73a6b33934Smacallan    }
74a6b33934Smacallan}
75a6b33934Smacallan
76a6b33934Smacallanstatic void
77a6b33934SmacallanPnozzSetCursorPosition(ScrnInfoPtr pScrn, int x, int y)
78a6b33934Smacallan{
79a6b33934Smacallan    PnozzPtr pPnozz = GET_PNOZZ_FROM_SCRN(pScrn);
80a6b33934Smacallan
81a6b33934Smacallan    pPnozz->Cursor.pos.x = x + 63;
82a6b33934Smacallan    pPnozz->Cursor.pos.y = y + 63;
83a6b33934Smacallan    pPnozz->Cursor.set = FB_CUR_SETPOS;
84a6b33934Smacallan    if (ioctl(pPnozz->psdp->fd, FBIOSCURSOR, &pPnozz->Cursor) == -1)
85a6b33934Smacallan	xf86Msg(X_ERROR, "FB_CUR_SETPOS failed\n");
86a6b33934Smacallan}
87a6b33934Smacallan
88a6b33934Smacallanstatic void
89a6b33934SmacallanPnozzSetCursorColors(ScrnInfoPtr pScrn, int bg, int fg)
90a6b33934Smacallan{
91a6b33934Smacallan    PnozzPtr pPnozz = GET_PNOZZ_FROM_SCRN(pScrn);
92a6b33934Smacallan
93a6b33934Smacallan    pPnozz->Cursor.set = FB_CUR_SETCMAP;
94a6b33934Smacallan    pPnozz->Cursor.cmap.red[0] = (bg & 0xff0000) >> 16;
95a6b33934Smacallan    pPnozz->Cursor.cmap.green[0] = (bg & 0xff00) >> 8;
96a6b33934Smacallan    pPnozz->Cursor.cmap.blue[0] = bg & 0xff;
97a6b33934Smacallan    pPnozz->Cursor.cmap.red[1] = (fg & 0xff0000) >> 16;
98a6b33934Smacallan    pPnozz->Cursor.cmap.green[1] = (fg & 0xff00) >> 8;
99a6b33934Smacallan    pPnozz->Cursor.cmap.blue[1] = fg & 0xff;
100a6b33934Smacallan    if (ioctl(pPnozz->psdp->fd, FBIOSCURSOR, &pPnozz->Cursor) == -1)
101a6b33934Smacallan	xf86Msg(X_ERROR, "FB_CUR_SETCMAP failed\n");
102a6b33934Smacallan}
103a6b33934Smacallan
104a6b33934SmacallanBool
105a6b33934SmacallanPnozzHWCursorInit(ScreenPtr pScreen)
106a6b33934Smacallan{
107a6b33934Smacallan    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
108a6b33934Smacallan    PnozzPtr pPnozz;
109a6b33934Smacallan    xf86CursorInfoPtr infoPtr;
110a6b33934Smacallan
111a6b33934Smacallan    pPnozz = GET_PNOZZ_FROM_SCRN(pScrn);
112a6b33934Smacallan
113a6b33934Smacallan    pPnozz->Cursor.mask = NULL;
114a6b33934Smacallan    pPnozz->Cursor.image = NULL;
115a6b33934Smacallan    if (ioctl(pPnozz->psdp->fd, FBIOGCURSOR, &pPnozz->Cursor) == -1) {
116a6b33934Smacallan    	xf86Msg(X_ERROR, "Hardware cursor isn't available\n");
117a6b33934Smacallan	return FALSE;
118a6b33934Smacallan    }
119a6b33934Smacallan
120a6b33934Smacallan    infoPtr = xf86CreateCursorInfoRec();
121a6b33934Smacallan    if(!infoPtr) return FALSE;
122a6b33934Smacallan
123a6b33934Smacallan    pPnozz->CursorInfoRec = infoPtr;
124a6b33934Smacallan
125a6b33934Smacallan    infoPtr->MaxWidth = 64;
126a6b33934Smacallan    infoPtr->MaxHeight = 64;
127a6b33934Smacallan
128a6b33934Smacallan    pPnozz->Cursor.hot.x = 63;
129a6b33934Smacallan    pPnozz->Cursor.hot.y = 63;
130a6b33934Smacallan    pPnozz->Cursor.set = FB_CUR_SETHOT;
131a6b33934Smacallan    ioctl(pPnozz->psdp->fd, FBIOSCURSOR, &pPnozz->Cursor);
132a6b33934Smacallan
133a6b33934Smacallan    pPnozz->Cursor.cmap.red = pPnozz->pal;
134a6b33934Smacallan    pPnozz->Cursor.cmap.green = pPnozz->pal + 3;
135a6b33934Smacallan    pPnozz->Cursor.cmap.blue = pPnozz->pal + 6;
136a6b33934Smacallan
137a6b33934Smacallan    infoPtr->Flags = HARDWARE_CURSOR_AND_SOURCE_WITH_MASK |
138a6b33934Smacallan	HARDWARE_CURSOR_TRUECOLOR_AT_8BPP /*|
139a6b33934Smacallan	HARDWARE_CURSOR_BIT_ORDER_MSBFIRST | HARDWARE_CURSOR_NIBBLE_SWAPPED*/;
140a6b33934Smacallan
141a6b33934Smacallan    infoPtr->SetCursorColors = PnozzSetCursorColors;
142a6b33934Smacallan    infoPtr->SetCursorPosition = PnozzSetCursorPosition;
143a6b33934Smacallan    infoPtr->LoadCursorImage = PnozzLoadCursorImage;
144a6b33934Smacallan    infoPtr->HideCursor = PnozzHideCursor;
145a6b33934Smacallan    infoPtr->ShowCursor = PnozzShowCursor;
146a6b33934Smacallan    infoPtr->UseHWCursor = NULL;
147a6b33934Smacallan
148a6b33934Smacallan    return xf86InitCursor(pScreen, infoPtr);
149a6b33934Smacallan}
150