vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / accelerants / ati / mach64_cursor.cpp
blobc397e34210257813f8633bbfd0f45800ad538646
1 /*
2 Copyright 2009 Haiku, Inc. All rights reserved.
3 Distributed under the terms of the MIT license.
5 Authors:
6 Gerald Zajac 2009
7 */
10 #include "accelerant.h"
11 #include "mach64.h"
13 #include <string.h>
17 void
18 Mach64_ShowCursor(bool bShow)
20 // Turn cursor on/off.
22 OUTREGM(GEN_TEST_CNTL, bShow ? HWCURSOR_ENABLE : 0, HWCURSOR_ENABLE);
26 void
27 Mach64_SetCursorPosition(int x, int y)
29 SharedInfo& si = *gInfo.sharedInfo;
31 // xOffset & yOffset are used for displaying partial cursors on screen edges.
33 uint8 xOffset = 0;
34 uint8 yOffset = 0;
36 if (x < 0) {
37 xOffset = -x;
38 x = 0;
41 if (y < 0) {
42 yOffset = -y;
43 y = 0;
46 OUTREG(CUR_OFFSET, (si.cursorOffset >> 3) + (yOffset << 1));
47 OUTREG(CUR_HORZ_VERT_OFF, (yOffset << 16) | xOffset);
48 OUTREG(CUR_HORZ_VERT_POSN, (y << 16) | x);
52 bool
53 Mach64_LoadCursorImage(int width, int height, uint8* andMask, uint8* xorMask)
55 SharedInfo& si = *gInfo.sharedInfo;
57 if (andMask == NULL || xorMask == NULL)
58 return false;
60 uint16* fbCursor = (uint16*)((addr_t)si.videoMemAddr + si.cursorOffset);
62 // Initialize the hardware cursor as completely transparent.
64 memset(fbCursor, 0xaa, CURSOR_BYTES);
66 // Now load the AND & XOR masks for the cursor image into the cursor
67 // buffer. Note that a particular bit in these masks will have the
68 // following effect upon the corresponding cursor pixel:
69 // AND XOR Result
70 // 0 0 White pixel
71 // 0 1 Black pixel
72 // 1 0 Screen color (for transparency)
73 // 1 1 Reverse screen color to black or white
75 for (int row = 0; row < height; row++) {
76 for (int colByte = 0; colByte < width / 8; colByte++) {
77 // Convert the 8 bit AND and XOR masks into a 16 bit mask containing
78 // pairs of the bits from the AND and XOR maks.
80 uint8 andBits = *andMask++;
81 uint8 xorBits = *xorMask++;
82 uint16 cursorBits = 0;
84 for (int j = 0; j < 8; j++) {
85 cursorBits <<= 2;
86 cursorBits |= ((andBits & 0x01) << 1);
87 cursorBits |= (xorBits & 0x01);
88 andBits >>= 1;
89 xorBits >>= 1;
92 fbCursor[row * 8 + colByte] = cursorBits;
96 // Set the cursor colors which are white background and black foreground.
98 OUTREG(CUR_CLR0, ~0);
99 OUTREG(CUR_CLR1, 0);
101 return true;