1 /* 2 Copyright 2009 Haiku, Inc. All rights reserved. 3 Distributed under the terms of the MIT license. 4 5 Authors: 6 Gerald Zajac 2009 7 */ 8 9 10 #include "accelerant.h" 11 #include "mach64.h" 12 13 #include <string.h> 14 15 16 17 void 18 Mach64_ShowCursor(bool bShow) 19 { 20 // Turn cursor on/off. 21 22 OUTREGM(GEN_TEST_CNTL, bShow ? HWCURSOR_ENABLE : 0, HWCURSOR_ENABLE); 23 } 24 25 26 void 27 Mach64_SetCursorPosition(int x, int y) 28 { 29 SharedInfo& si = *gInfo.sharedInfo; 30 31 // xOffset & yOffset are used for displaying partial cursors on screen edges. 32 33 uint8 xOffset = 0; 34 uint8 yOffset = 0; 35 36 if (x < 0) { 37 xOffset = -x; 38 x = 0; 39 } 40 41 if (y < 0) { 42 yOffset = -y; 43 y = 0; 44 } 45 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); 49 } 50 51 52 bool 53 Mach64_LoadCursorImage(int width, int height, uint8* andMask, uint8* xorMask) 54 { 55 SharedInfo& si = *gInfo.sharedInfo; 56 57 if (andMask == NULL || xorMask == NULL) 58 return false; 59 60 uint16* fbCursor = (uint16*)((addr_t)si.videoMemAddr + si.cursorOffset); 61 62 // Initialize the hardware cursor as completely transparent. 63 64 memset(fbCursor, 0xaa, CURSOR_BYTES); 65 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 74 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. 79 80 uint8 andBits = *andMask++; 81 uint8 xorBits = *xorMask++; 82 uint16 cursorBits = 0; 83 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; 90 } 91 92 fbCursor[row * 8 + colByte] = cursorBits; 93 } 94 } 95 96 // Set the cursor colors which are white background and black foreground. 97 98 OUTREG(CUR_CLR0, ~0); 99 OUTREG(CUR_CLR1, 0); 100 101 return true; 102 } 103