1
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/cirrus/alp_hwcurs.c,v 1.5 2001/05/07 21:59:06 tsi Exp $ */
6
#include "xf86_OSproc.h"
7
#include "xf86_ansic.h"
11
#include "xf86PciInfo.h"
19
#define CURSORWIDTH pAlp->CursorWidth
20
#define CURSORHEIGHT pAlp->CursorHeight
21
#define CURSORSIZE (CURSORWIDTH*CURSORHEIGHT/8)
22
#define MAXCURSORSIZE (64*64>>3)
25
AlpSetCursorColors(ScrnInfoPtr pScrn, int bg, int fg)
27
const AlpPtr pAlp = ALPPTR(CIRPTR(pScrn));
28
vgaHWPtr hwp = VGAHWPTR(pScrn);
30
ErrorF("AlpSetCursorColors\n");
32
hwp->writeSeq(hwp, 0x12, pAlp->ModeReg.ExtVga[SR12]|0x02);
33
hwp->writeDacWriteAddr(hwp, 0x00);
34
hwp->writeDacData(hwp, 0x3f & (bg >> 18));
35
hwp->writeDacData(hwp, 0x3f & (bg >> 10));
36
hwp->writeDacData(hwp, 0x3f & (bg >> 2));
37
hwp->writeDacWriteAddr(hwp, 0x0F);
38
hwp->writeDacData(hwp, 0x3F & (fg >> 18));
39
hwp->writeDacData(hwp, 0x3F & (fg >> 10));
40
hwp->writeDacData(hwp, 0x3F & (fg >> 2));
41
hwp->writeSeq(hwp, 0x12, pAlp->ModeReg.ExtVga[SR12]);
45
AlpLoadSkewedCursor(CirPtr pCir, int x, int y) {
47
const AlpPtr pAlp = ALPPTR(pCir);
49
unsigned char *memx = pAlp->HWCursorBits;
50
unsigned char *CursorBits = pAlp->CursorBits;
52
unsigned char mem[2*MAXCURSORSIZE];
53
unsigned char *p1, *p2;
55
Bool cur64 = (CURSORWIDTH == 64);
56
int shift = (cur64? 1 : 0);
58
if (x > 0) x = 0; else x = -x;
59
if (y > 0) y = 0; else y = -y;
62
a = ((y*CURSORWIDTH<<shift)+x)>>3;
65
/* Copy the skewed mask bits */
68
for (i = 0; i < (CURSORSIZE << shift)-a-1; i++) {
69
*p1++ = (p2[0] << b) | (p2[1] >> (8-b));
75
/* Clear to end (bottom) of mask. */
76
for (i = i+1; i < (CURSORSIZE << shift); i++)
80
/* Now copy the cursor bits */
81
/* p1 is already right */
82
p2 = CursorBits+CURSORSIZE+a;
83
for (i = 0; i < CURSORSIZE-a-1; i++) {
84
*p1++ = (p2[0] << b) | (p2[1] >> (8-b));
87
/* last cursor byte */
91
/* Clear to end (bottom) of cursor. */
92
for (i = i+1; i < CURSORSIZE; i++)
95
/* Clear the right unused area of the mask
97
p2 = mem + CURSORWIDTH/8 - (x>>3) - 1;
98
for (i = 0; i < 2*CURSORHEIGHT; i++) {
102
for (j = x>>3; j >= 0; j--) {
108
memcpy(memx, mem, 2*CURSORSIZE);
113
AlpSetCursorPosition(ScrnInfoPtr pScrn, int x, int y)
115
const CirPtr pCir = CIRPTR(pScrn);
116
const AlpPtr pAlp = ALPPTR(pCir);
117
vgaHWPtr hwp = VGAHWPTR(pScrn);
121
ErrorF("AlpSetCursorPosition %d %d\n", x, y);
125
if (x < 0 || y < 0) {
126
if (x+CURSORWIDTH <= 0 || y+CURSORHEIGHT <= 0) {
127
hwp->writeSeq(hwp, 0x12, pAlp->ModeReg.ExtVga[SR12] & ~0x01);
130
AlpLoadSkewedCursor(pCir, x, y);
131
pCir->CursorIsSkewed = TRUE;
134
} else if (pCir->CursorIsSkewed) {
135
memcpy(pAlp->HWCursorBits, pAlp->CursorBits, 2*CURSORSIZE);
136
pCir->CursorIsSkewed = FALSE;
138
hwp->writeSeq(hwp, 0x12, pAlp->ModeReg.ExtVga[SR12]);
139
hwp->writeSeq(hwp, ((x << 5)|0x10)&0xff, x >> 3);
140
hwp->writeSeq(hwp, ((y << 5)|0x11)&0xff, y >> 3);
144
AlpLoadCursorImage(ScrnInfoPtr pScrn, unsigned char *bits)
146
const AlpPtr pAlp = ALPPTR(CIRPTR(pScrn));
147
vgaHWPtr hwp = VGAHWPTR(pScrn);
150
ErrorF("AlpLoadCursorImage\n");
153
pAlp->CursorBits = bits;
154
memcpy(pAlp->HWCursorBits, bits, 2*CURSORSIZE);
155
/* this should work for both 64 and 32 bit cursors */
156
pAlp->ModeReg.ExtVga[SR13] = 0x3f;
157
hwp->writeSeq(hwp, 0x13, pAlp->ModeReg.ExtVga[SR13]);
161
AlpHideCursor(ScrnInfoPtr pScrn)
163
AlpPtr pAlp = ALPPTR(CIRPTR(pScrn));
164
vgaHWPtr hwp = VGAHWPTR(pScrn);
167
ErrorF("AlpHideCursor\n");
169
pAlp->ModeReg.ExtVga[SR12] &= ~0x01;
170
hwp->writeSeq(hwp, 0x12, pAlp->ModeReg.ExtVga[SR12]);
174
AlpShowCursor(ScrnInfoPtr pScrn)
176
AlpPtr pAlp = ALPPTR(CIRPTR(pScrn));
177
vgaHWPtr hwp = VGAHWPTR(pScrn);
180
ErrorF("AlpShowCursor\n");
182
pAlp->ModeReg.ExtVga[SR12] |= 0x01;
183
hwp->writeSeq(hwp, 0x12, pAlp->ModeReg.ExtVga[SR12]);
187
AlpUseHWCursor(ScreenPtr pScreen, CursorPtr pCurs)
189
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
191
ErrorF("AlpUseHWCursor\n");
193
if (pScrn->bitsPerPixel < 8)
200
AlpHWCursorInit(ScreenPtr pScreen, int size)
202
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
203
const CirPtr pCir = CIRPTR(pScrn);
204
const AlpPtr pAlp = ALPPTR(pCir);
206
xf86CursorInfoPtr infoPtr;
209
ErrorF("AlpHWCursorInit\n");
211
if (!size) return FALSE;
213
infoPtr = xf86CreateCursorInfoRec();
214
if (!infoPtr) return FALSE;
216
pCir->CursorInfoRec = infoPtr;
217
pCir->CursorIsSkewed = FALSE;
218
pAlp->CursorBits = NULL;
221
CURSORWIDTH = CURSORHEIGHT = 64;
223
CURSORWIDTH = CURSORHEIGHT = 32;
225
pAlp->HWCursorBits = pCir->FbBase + 1024*pScrn->videoRam - 2*CURSORSIZE;
227
infoPtr->MaxWidth = CURSORWIDTH;
228
infoPtr->MaxHeight = CURSORHEIGHT;
229
if (CURSORWIDTH == 64)
231
#if X_BYTE_ORDER == X_LITTLE_ENDIAN
232
HARDWARE_CURSOR_BIT_ORDER_MSBFIRST |
234
HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
235
HARDWARE_CURSOR_TRUECOLOR_AT_8BPP;
238
#if X_BYTE_ORDER == X_LITTLE_ENDIAN
239
HARDWARE_CURSOR_BIT_ORDER_MSBFIRST |
241
HARDWARE_CURSOR_TRUECOLOR_AT_8BPP;
243
infoPtr->SetCursorColors = AlpSetCursorColors;
244
infoPtr->SetCursorPosition = AlpSetCursorPosition;
245
infoPtr->LoadCursorImage = AlpLoadCursorImage;
246
infoPtr->HideCursor = AlpHideCursor;
247
infoPtr->ShowCursor = AlpShowCursor;
248
infoPtr->UseHWCursor = AlpUseHWCursor;
251
ErrorF("AlpHWCursorInit before xf86InitCursor\n");
253
xf86DrvMsg(pScrn->scrnIndex,X_INFO,"Hardware cursor: %ix%i\n",
254
CURSORWIDTH,CURSORHEIGHT);
255
return(xf86InitCursor(pScreen, infoPtr));