xref: /haiku/src/add-ons/accelerants/3dfx/3dfx_cursor.cpp (revision a56bc48835ebabc25dfd5ec8a6a52e3cd5906bb1)
1 /*
2 	Copyright 2010 Haiku, Inc.  All rights reserved.
3 	Distributed under the terms of the MIT license.
4 
5 	Authors:
6 	Gerald Zajac 2010
7 */
8 
9 
10 #include "accelerant.h"
11 #include "3dfx.h"
12 
13 #include <string.h>
14 
15 
16 
17 void
TDFX_ShowCursor(bool bShow)18 TDFX_ShowCursor(bool bShow)
19 {
20 	// Turn cursor on/off.
21 
22 	uint32 config = INREG32(VIDEO_PROC_CONFIG);
23 	if (bShow)
24 		config |= CURSOR_ENABLE;
25 	else
26 		config &= ~CURSOR_ENABLE;
27 
28 	TDFX_WaitForFifo(1);
29 	OUTREG32(VIDEO_PROC_CONFIG, config);
30 }
31 
32 
33 void
TDFX_SetCursorPosition(int x,int y)34 TDFX_SetCursorPosition(int x, int y)
35 {
36 	TDFX_WaitForFifo(1);
37 	OUTREG32(HW_CURSOR_LOC, ((y + 63) << 16) | (x + 63));
38 }
39 
40 
41 bool
TDFX_LoadCursorImage(int width,int height,uint8 * andMask,uint8 * xorMask)42 TDFX_LoadCursorImage(int width, int height, uint8* andMask, uint8* xorMask)
43 {
44 	SharedInfo& si = *gInfo.sharedInfo;
45 
46 	if (andMask == NULL || xorMask == NULL)
47 		return false;
48 
49 	uint64* fbCursor64 = (uint64*)((addr_t)si.videoMemAddr + si.cursorOffset);
50 
51 	// Initialize the hardware cursor as completely transparent.
52 
53 	for (int i = 0; i < CURSOR_BYTES; i += 16) {
54 		*fbCursor64++ = ~0;		// and bits
55 		*fbCursor64++ = 0;		// xor bits
56 	}
57 
58 	// Now load the AND & XOR masks for the cursor image into the cursor
59 	// buffer.  Note that a particular bit in these masks will have the
60 	// following effect upon the corresponding cursor pixel:
61 	//	AND  XOR	Result
62 	//	 0    0		 White pixel
63 	//	 0    1		 Black pixel
64 	//	 1    0		 Screen color (for transparency)
65 	//	 1    1		 Reverse screen color to black or white
66 
67 	uint8* fbCursor = (uint8*)((addr_t)si.videoMemAddr + si.cursorOffset);
68 
69 	for (int row = 0; row < height; row++) {
70 		for (int colByte = 0; colByte < width / 8; colByte++) {
71 			fbCursor[row * 16 + colByte] = *andMask++;
72 			fbCursor[row * 16 + colByte + 8] = *xorMask++;
73 		}
74 	}
75 
76 	// Set the cursor colors which are white background and black foreground.
77 
78 	TDFX_WaitForFifo(2);
79 	OUTREG32(HW_CURSOR_COLOR0, 0xffffff);
80 	OUTREG32(HW_CURSOR_COLOR1, 0);
81 
82 	return true;
83 }
84