2
* Id: s3curs.c,v 1.1 1999/11/02 08:17:24 keithp Exp $
4
* Copyright ļæ½ 1999 Keith Packard
6
* Permission to use, copy, modify, distribute, and sell this software and its
7
* documentation for any purpose is hereby granted without fee, provided that
8
* the above copyright notice appear in all copies and that both that
9
* copyright notice and this permission notice appear in supporting
10
* documentation, and that the name of Keith Packard not be used in
11
* advertising or publicity pertaining to distribution of the software without
12
* specific, written prior permission. Keith Packard makes no
13
* representations about the suitability of this software for any purpose. It
14
* is provided "as is" without express or implied warranty.
16
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22
* PERFORMANCE OF THIS SOFTWARE.
24
/* $RCSId: xc/programs/Xserver/hw/kdrive/trio/s3curs.c,v 1.2 1999/12/30 03:03:19 robin Exp $ */
27
#include <kdrive-config.h>
31
#include "cursorstr.h"
33
#define SetupCursor(s) KdScreenPriv(s); \
34
s3CardInfo(pScreenPriv); \
35
s3ScreenInfo(pScreenPriv); \
37
S3Cursor *pCurPriv = &s3s->cursor
40
_s3MoveCursor (ScreenPtr pScreen, int x, int y)
43
CARD8 xlow, xhigh, ylow, yhigh;
61
xhigh = (CARD8) (x >> 8);
63
yhigh = (CARD8) (y >> 8);
66
/* This is the recommended order to move the cursor */
68
_s3WriteIndexRegister (&s3->crt_vga_3d4, 0x46, xhigh);
69
_s3WriteIndexRegister (&s3->crt_vga_3d4, 0x47, xlow);
70
_s3WriteIndexRegister (&s3->crt_vga_3d4, 0x49, ylow);
71
_s3WriteIndexRegister (&s3->crt_vga_3d4, 0x4e, xoff);
72
_s3WriteIndexRegister (&s3->crt_vga_3d4, 0x4f, yoff);
73
_s3WriteIndexRegister (&s3->crt_vga_3d4, 0x48, yhigh);
77
s3MoveCursor (ScreenPtr pScreen, int x, int y)
79
SetupCursor (pScreen);
81
if (!pCurPriv->has_cursor)
84
if (!pScreenPriv->enabled)
89
_s3MoveCursor (pScreen, x, y);
95
s3AllocCursorColors (ScreenPtr pScreen)
97
SetupCursor (pScreen);
98
CursorPtr pCursor = pCurPriv->pCursor;
99
xColorItem sourceColor, maskColor;
101
KdAllocateCursorPixels (pScreen, 0, pCursor,
102
&pCurPriv->source, &pCurPriv->mask);
103
switch (pScreenPriv->screen->fb[0].bitsPerPixel) {
105
pCurPriv->source |= pCurPriv->source << 4;
106
pCurPriv->mask |= pCurPriv->mask << 4;
108
pCurPriv->source |= pCurPriv->source << 8;
109
pCurPriv->mask |= pCurPriv->mask << 8;
111
pCurPriv->source |= pCurPriv->source << 16;
112
pCurPriv->mask |= pCurPriv->mask << 16;
117
_s3SetCursorColors (ScreenPtr pScreen)
119
SetupCursor (pScreen);
121
/* Reset cursor color stack pointers */
122
(void) _s3ReadIndexRegister(&s3->crt_vga_3d4, 0x45);
123
_s3WriteIndexRegister (&s3->crt_vga_3d4, 0x4a, pCurPriv->source);
124
_s3WriteIndexRegister (&s3->crt_vga_3d4, 0x4a, pCurPriv->source >> 8);
125
_s3WriteIndexRegister (&s3->crt_vga_3d4, 0x4a, pCurPriv->source >> 16);
128
/* Reset cursor color stack pointers */
129
(void) _s3ReadIndexRegister(&s3->crt_vga_3d4, 0x45);
130
_s3WriteIndexRegister (&s3->crt_vga_3d4, 0x4b, pCurPriv->mask);
131
_s3WriteIndexRegister (&s3->crt_vga_3d4, 0x4b, pCurPriv->mask >> 8);
132
_s3WriteIndexRegister (&s3->crt_vga_3d4, 0x4b, pCurPriv->mask >> 16);
136
s3RecolorCursor (ScreenPtr pScreen, int ndef, xColorItem *pdef)
138
SetupCursor (pScreen);
139
CursorPtr pCursor = pCurPriv->pCursor;
140
xColorItem sourceColor, maskColor;
142
if (!pCurPriv->has_cursor || !pCursor)
145
if (!pScreenPriv->enabled)
152
if (pdef->pixel == pCurPriv->source ||
153
pdef->pixel == pCurPriv->mask)
160
s3AllocCursorColors (pScreen);
163
_s3SetCursorColors (pScreen);
169
s3LoadCursor (ScreenPtr pScreen, int x, int y)
171
SetupCursor(pScreen);
172
CursorPtr pCursor = pCurPriv->pCursor;
173
CursorBitsPtr bits = pCursor->bits;
175
unsigned char r[2], g[2], b[2];
177
unsigned long *msk, *mskLine, *src, *srcLine;
178
unsigned long and, xor;
182
unsigned char ramdac_control_;
185
* Allocate new colors
187
s3AllocCursorColors (pScreen);
189
pCurPriv->pCursor = pCursor;
190
pCurPriv->xhot = pCursor->bits->xhot;
191
pCurPriv->yhot = pCursor->bits->yhot;
194
* Stick new image into cursor memory
196
ram = (unsigned long *) s3s->cursor_base;
197
mskLine = (unsigned long *) bits->mask;
198
srcLine = (unsigned long *) bits->source;
201
if (h > S3_CURSOR_HEIGHT)
202
h = S3_CURSOR_HEIGHT;
204
wsrc = BitmapBytePad(bits->width) / 4; /* ulongs per line */
206
for (i = 0; i < S3_CURSOR_HEIGHT; i++)
212
for (j = 0; j < S3_CURSOR_WIDTH / 32; j++) {
216
if (i < h && j < wsrc)
231
*ram++ = (and & 0xffff) | (xor << 16);
232
*ram++ = (and >> 16) | (xor & 0xffff0000);
240
_s3SetCursorColors (pScreen);
242
/* Enable the cursor */
243
_s3WriteIndexRegister (&s3->crt_vga_3d4, 0x45, 0x01);
245
/* Wait for VRetrace to make sure the position is read */
246
_s3WaitVRetrace (s3);
248
/* Move to new position */
249
_s3MoveCursor (pScreen, x, y);
256
s3UnloadCursor (ScreenPtr pScreen)
258
SetupCursor (pScreen);
264
_s3WriteIndexRegister (&s3->crt_vga_3d4, 0x45, 0);
271
s3RealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
273
SetupCursor(pScreen);
275
if (!pScreenPriv->enabled)
278
/* miRecolorCursor does this */
279
if (pCurPriv->pCursor == pCursor)
289
miPointerPosition (&x, &y);
290
s3LoadCursor (pScreen, x, y);
297
s3UnrealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
303
s3SetCursor (ScreenPtr pScreen, CursorPtr pCursor, int x, int y)
305
SetupCursor(pScreen);
307
pCurPriv->pCursor = pCursor;
309
if (!pScreenPriv->enabled)
313
s3LoadCursor (pScreen, x, y);
315
s3UnloadCursor (pScreen);
318
miPointerSpriteFuncRec s3PointerSpriteFuncs = {
326
s3QueryBestSize (int class,
327
unsigned short *pwidth, unsigned short *pheight,
330
SetupCursor (pScreen);
335
if (*pwidth > pCurPriv->width)
336
*pwidth = pCurPriv->width;
337
if (*pheight > pCurPriv->height)
338
*pheight = pCurPriv->height;
339
if (*pwidth > pScreen->width)
340
*pwidth = pScreen->width;
341
if (*pheight > pScreen->height)
342
*pheight = pScreen->height;
345
fbQueryBestSize (class, pwidth, pheight, pScreen);
351
s3CursorInit (ScreenPtr pScreen)
353
SetupCursor (pScreen);
355
if (!s3s->cursor_base)
357
pCurPriv->has_cursor = FALSE;
361
pCurPriv->width = S3_CURSOR_WIDTH;
362
pCurPriv->height= S3_CURSOR_HEIGHT;
363
pScreen->QueryBestSize = s3QueryBestSize;
364
miPointerInitialize (pScreen,
365
&s3PointerSpriteFuncs,
366
&kdPointerScreenFuncs,
368
pCurPriv->has_cursor = TRUE;
369
pCurPriv->pCursor = NULL;
374
s3CursorEnable (ScreenPtr pScreen)
376
SetupCursor (pScreen);
378
if (pCurPriv->has_cursor)
380
if (pCurPriv->pCursor)
388
miPointerPosition (&x, &y);
389
s3LoadCursor (pScreen, x, y);
392
s3UnloadCursor (pScreen);
397
s3CursorDisable (ScreenPtr pScreen)
399
SetupCursor (pScreen);
401
if (!pScreenPriv->enabled)
404
if (pCurPriv->has_cursor)
406
if (pCurPriv->pCursor)
408
s3UnloadCursor (pScreen);
414
s3CursorFini (ScreenPtr pScreen)
416
SetupCursor (pScreen);
418
pCurPriv->pCursor = NULL;