hcrx_cursor.c revision 1f9ea1ac
1/* $NetBSD: hcrx_cursor.c,v 1.1 2025/12/22 13:07:11 macallan Exp $ */ 2/* 3 * Copyright (c) 2025 Michael Lorenz 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * - Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * - Redistributions in binary form must reproduce the above 13 * copyright notice, this list of conditions and the following 14 * disclaimer in the documentation and/or other materials provided 15 * with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 21 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 * 30 */ 31 32#include <sys/types.h> 33#include <dev/ic/nglereg.h> 34#include "ngle.h" 35 36static void HCRXLoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src); 37static void HCRXSetCursorPosition(ScrnInfoPtr pScrn, int x, int y); 38static void HCRXSetCursorColors(ScrnInfoPtr pScrn, int bg, int fg); 39 40static void 41HCRXLoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src) 42{ 43 NGLEPtr pNGLE = NGLEPTR(pScrn); 44 uint32_t latch; 45 int i; 46 47 /* image first */ 48 NGLEWrite4(pNGLE, NGLE_HCRX_CURSOR_ADDR, 0x80); 49 for (i = 0; i < 128; i++) { 50 memcpy(&latch, src, 4); 51 NGLEWrite4(pNGLE, NGLE_HCRX_CURSOR_DATA, latch); 52 src += 4; 53 } 54 55 /* and now the mask */ 56 NGLEWrite4(pNGLE, NGLE_HCRX_CURSOR_ADDR, 0); 57 for (i = 0; i < 128; i++) { 58 memcpy(&latch, src, 4); 59 NGLEWrite4(pNGLE, NGLE_HCRX_CURSOR_DATA, latch); 60 src += 4; 61 } 62} 63 64void 65HCRXShowCursor(ScrnInfoPtr pScrn) 66{ 67 NGLEPtr pNGLE = NGLEPTR(pScrn); 68 69 pNGLE->cursor.enable = 1; 70 NGLEWrite4(pNGLE, NGLE_HCRX_CURSOR, pNGLE->creg | HCRX_ENABLE_CURSOR); 71} 72 73void 74HCRXHideCursor(ScrnInfoPtr pScrn) 75{ 76 NGLEPtr pNGLE = NGLEPTR(pScrn); 77 78 pNGLE->cursor.enable = 0; 79 NGLEWrite4(pNGLE, NGLE_HCRX_CURSOR, pNGLE->creg); 80} 81 82static void 83HCRXSetCursorPosition(ScrnInfoPtr pScrn, int x, int y) 84{ 85 NGLEPtr pNGLE = NGLEPTR(pScrn); 86 87 if (x < 0) 88 x = 0x1000 - x; 89 if (y < 0) 90 y = 0x1000 - y; 91 pNGLE->creg = (x << 16) | y; 92 NGLEWrite4(pNGLE, NGLE_HCRX_CURSOR, pNGLE->creg | 93 (pNGLE->cursor.enable ? HCRX_ENABLE_CURSOR : 0)); 94} 95 96static void 97HCRXSetCursorColors(ScrnInfoPtr pScrn, int bg, int fg) 98{ 99 NGLEPtr pNGLE = NGLEPTR(pScrn); 100 uint8_t stat; 101 102 do { 103 stat = NGLERead1(pNGLE, NGLE_BUSY); 104 if (stat == 0) 105 stat = NGLERead1(pNGLE, NGLE_BUSY); 106 } while (stat != 0); 107 108 NGLEWrite4(pNGLE, NGLE_BAboth, 109 BA(FractDcd, Otc01, Ots08, Addr24, 0, BINcmap, 0)); 110 NGLEWrite4(pNGLE, NGLE_IBO, 111 IBOvals(RopSrc, 0, BitmapExtent08, 0, DataDynamic, MaskOtc, 0, 0)); 112 NGLEWrite4(pNGLE, NGLE_PLANEMASK, 0xffffffff); 113 NGLEWrite4(pNGLE, NGLE_BINC_DST, 0); 114 NGLEWrite4(pNGLE, NGLE_BINC_DATA_R, bg); 115 NGLEWrite4(pNGLE, NGLE_BINC_DATA_R, fg); 116 NGLEWrite4(pNGLE, NGLE_BINC_SRC, 0); 117 NGLEWrite4(pNGLE, NGLE_HCRX_LUTBLT, LBC_ENABLE | LBC_TYPE_CURSOR | 4); 118 pNGLE->hwmode = -1; 119} 120 121Bool 122HCRXSetupCursor(ScreenPtr pScreen) 123{ 124 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 125 NGLEPtr pNGLE = NGLEPTR(pScrn); 126 xf86CursorInfoPtr infoPtr; 127 128 pNGLE->cursor.enable = 0; 129 pNGLE->creg = 0; 130 131 infoPtr = xf86CreateCursorInfoRec(); 132 if(!infoPtr) return FALSE; 133 134 pNGLE->CursorInfoRec = infoPtr; 135 136 xf86Msg(X_INFO, "HCRX HW cursor enabled\n"); 137 138 infoPtr->MaxWidth = 64; 139 infoPtr->MaxHeight = 64; 140 pNGLE->maskoffset = 8 * 64; 141 142 infoPtr->Flags = HARDWARE_CURSOR_AND_SOURCE_WITH_MASK | 143 HARDWARE_CURSOR_TRUECOLOR_AT_8BPP; 144 145 infoPtr->SetCursorColors = HCRXSetCursorColors; 146 infoPtr->SetCursorPosition = HCRXSetCursorPosition; 147 infoPtr->LoadCursorImage = HCRXLoadCursorImage; 148 infoPtr->HideCursor = HCRXHideCursor; 149 infoPtr->ShowCursor = HCRXShowCursor; 150 infoPtr->UseHWCursor = NULL; 151 152 return xf86InitCursor(pScreen, infoPtr); 153} 154