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 */ 23f55eacdeSjdc/* $NetBSD: pnozz_cursor.c,v 1.3 2021/05/27 04:48:10 jdc Exp $ */ 24f55eacdeSjdc 25f55eacdeSjdc#ifdef HAVE_CONFIG_H 26f55eacdeSjdc#include "config.h" 27f55eacdeSjdc#endif 28a6b33934Smacallan 29a6b33934Smacallan#include <fcntl.h> 30a6b33934Smacallan#include <sys/time.h> 31a6b33934Smacallan#include <sys/types.h> 32d046d9f8Smacallan#include <sys/ioctl.h> 33a6b33934Smacallan#include <dev/wscons/wsconsio.h> 34a6b33934Smacallan 35a6b33934Smacallan#include "pnozz.h" 36a6b33934Smacallan 37a6b33934Smacallanstatic void PnozzLoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src); 38a6b33934Smacallanstatic void PnozzSetCursorPosition(ScrnInfoPtr pScrn, int x, int y); 39a6b33934Smacallanstatic void PnozzSetCursorColors(ScrnInfoPtr pScrn, int bg, int fg); 40a6b33934Smacallan 41a6b33934Smacallanstatic void 42a6b33934SmacallanPnozzLoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src) 43a6b33934Smacallan{ 44a6b33934Smacallan PnozzPtr pPnozz = GET_PNOZZ_FROM_SCRN(pScrn); 45a6b33934Smacallan 46a6b33934Smacallan pPnozz->Cursor.set = FB_CUR_SETSHAPE; 47a6b33934Smacallan pPnozz->Cursor.image = src; 48a6b33934Smacallan pPnozz->Cursor.mask = src + 0x200; 49a6b33934Smacallan 50a6b33934Smacallan if (ioctl(pPnozz->psdp->fd, FBIOSCURSOR, &pPnozz->Cursor) == -1) 51a6b33934Smacallan xf86Msg(X_ERROR, "FB_CUR_SETSHAPE failed\n"); 52a6b33934Smacallan} 53a6b33934Smacallan 54a6b33934Smacallanvoid 55a6b33934SmacallanPnozzShowCursor(ScrnInfoPtr pScrn) 56a6b33934Smacallan{ 57a6b33934Smacallan PnozzPtr pPnozz = GET_PNOZZ_FROM_SCRN(pScrn); 58a6b33934Smacallan 59a6b33934Smacallan if (pPnozz->Cursor.enable == 0) { 60a6b33934Smacallan pPnozz->Cursor.enable = 1; 61a6b33934Smacallan pPnozz->Cursor.set = FB_CUR_SETCUR; 62a6b33934Smacallan if (ioctl(pPnozz->psdp->fd, FBIOSCURSOR, &pPnozz->Cursor) == -1) 63a6b33934Smacallan xf86Msg(X_ERROR, "FB_CUR_SETCUR failed\n"); 64a6b33934Smacallan } 65a6b33934Smacallan} 66a6b33934Smacallan 67a6b33934Smacallanvoid 68a6b33934SmacallanPnozzHideCursor(ScrnInfoPtr pScrn) 69a6b33934Smacallan{ 70a6b33934Smacallan PnozzPtr pPnozz = GET_PNOZZ_FROM_SCRN(pScrn); 71a6b33934Smacallan 72a6b33934Smacallan if (pPnozz->Cursor.enable == 1) { 73a6b33934Smacallan pPnozz->Cursor.enable = 0; 74a6b33934Smacallan pPnozz->Cursor.set = FB_CUR_SETCUR; 75a6b33934Smacallan if (ioctl(pPnozz->psdp->fd, FBIOSCURSOR, &pPnozz->Cursor) == -1) 76a6b33934Smacallan xf86Msg(X_ERROR, "FB_CUR_SETCUR failed\n"); 77a6b33934Smacallan } 78a6b33934Smacallan} 79a6b33934Smacallan 80a6b33934Smacallanstatic void 81a6b33934SmacallanPnozzSetCursorPosition(ScrnInfoPtr pScrn, int x, int y) 82a6b33934Smacallan{ 83a6b33934Smacallan PnozzPtr pPnozz = GET_PNOZZ_FROM_SCRN(pScrn); 84a6b33934Smacallan 85a6b33934Smacallan pPnozz->Cursor.pos.x = x + 63; 86a6b33934Smacallan pPnozz->Cursor.pos.y = y + 63; 87a6b33934Smacallan pPnozz->Cursor.set = FB_CUR_SETPOS; 88a6b33934Smacallan if (ioctl(pPnozz->psdp->fd, FBIOSCURSOR, &pPnozz->Cursor) == -1) 89a6b33934Smacallan xf86Msg(X_ERROR, "FB_CUR_SETPOS failed\n"); 90a6b33934Smacallan} 91a6b33934Smacallan 92a6b33934Smacallanstatic void 93a6b33934SmacallanPnozzSetCursorColors(ScrnInfoPtr pScrn, int bg, int fg) 94a6b33934Smacallan{ 95a6b33934Smacallan PnozzPtr pPnozz = GET_PNOZZ_FROM_SCRN(pScrn); 96a6b33934Smacallan 97a6b33934Smacallan pPnozz->Cursor.set = FB_CUR_SETCMAP; 98a6b33934Smacallan pPnozz->Cursor.cmap.red[0] = (bg & 0xff0000) >> 16; 99a6b33934Smacallan pPnozz->Cursor.cmap.green[0] = (bg & 0xff00) >> 8; 100a6b33934Smacallan pPnozz->Cursor.cmap.blue[0] = bg & 0xff; 101a6b33934Smacallan pPnozz->Cursor.cmap.red[1] = (fg & 0xff0000) >> 16; 102a6b33934Smacallan pPnozz->Cursor.cmap.green[1] = (fg & 0xff00) >> 8; 103a6b33934Smacallan pPnozz->Cursor.cmap.blue[1] = fg & 0xff; 104a6b33934Smacallan if (ioctl(pPnozz->psdp->fd, FBIOSCURSOR, &pPnozz->Cursor) == -1) 105a6b33934Smacallan xf86Msg(X_ERROR, "FB_CUR_SETCMAP failed\n"); 106a6b33934Smacallan} 107a6b33934Smacallan 108a6b33934SmacallanBool 109a6b33934SmacallanPnozzHWCursorInit(ScreenPtr pScreen) 110a6b33934Smacallan{ 111a6b33934Smacallan ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 112a6b33934Smacallan PnozzPtr pPnozz; 113a6b33934Smacallan xf86CursorInfoPtr infoPtr; 114a6b33934Smacallan 115a6b33934Smacallan pPnozz = GET_PNOZZ_FROM_SCRN(pScrn); 116a6b33934Smacallan 117a6b33934Smacallan pPnozz->Cursor.mask = NULL; 118a6b33934Smacallan pPnozz->Cursor.image = NULL; 119a6b33934Smacallan if (ioctl(pPnozz->psdp->fd, FBIOGCURSOR, &pPnozz->Cursor) == -1) { 120a6b33934Smacallan xf86Msg(X_ERROR, "Hardware cursor isn't available\n"); 121a6b33934Smacallan return FALSE; 122a6b33934Smacallan } 123a6b33934Smacallan 124a6b33934Smacallan infoPtr = xf86CreateCursorInfoRec(); 125a6b33934Smacallan if(!infoPtr) return FALSE; 126a6b33934Smacallan 127a6b33934Smacallan pPnozz->CursorInfoRec = infoPtr; 128a6b33934Smacallan 129a6b33934Smacallan infoPtr->MaxWidth = 64; 130a6b33934Smacallan infoPtr->MaxHeight = 64; 131a6b33934Smacallan 132a6b33934Smacallan pPnozz->Cursor.hot.x = 63; 133a6b33934Smacallan pPnozz->Cursor.hot.y = 63; 134a6b33934Smacallan pPnozz->Cursor.set = FB_CUR_SETHOT; 135a6b33934Smacallan ioctl(pPnozz->psdp->fd, FBIOSCURSOR, &pPnozz->Cursor); 136a6b33934Smacallan 137a6b33934Smacallan pPnozz->Cursor.cmap.red = pPnozz->pal; 138a6b33934Smacallan pPnozz->Cursor.cmap.green = pPnozz->pal + 3; 139a6b33934Smacallan pPnozz->Cursor.cmap.blue = pPnozz->pal + 6; 140a6b33934Smacallan 141a6b33934Smacallan infoPtr->Flags = HARDWARE_CURSOR_AND_SOURCE_WITH_MASK | 142a6b33934Smacallan HARDWARE_CURSOR_TRUECOLOR_AT_8BPP /*| 143a6b33934Smacallan HARDWARE_CURSOR_BIT_ORDER_MSBFIRST | HARDWARE_CURSOR_NIBBLE_SWAPPED*/; 144a6b33934Smacallan 145a6b33934Smacallan infoPtr->SetCursorColors = PnozzSetCursorColors; 146a6b33934Smacallan infoPtr->SetCursorPosition = PnozzSetCursorPosition; 147a6b33934Smacallan infoPtr->LoadCursorImage = PnozzLoadCursorImage; 148a6b33934Smacallan infoPtr->HideCursor = PnozzHideCursor; 149a6b33934Smacallan infoPtr->ShowCursor = PnozzShowCursor; 150a6b33934Smacallan infoPtr->UseHWCursor = NULL; 151a6b33934Smacallan 152a6b33934Smacallan return xf86InitCursor(pScreen, infoPtr); 153a6b33934Smacallan} 154