home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / ibm8514 / brcCurs.c < prev    next >
C/C++ Source or Header  |  1991-09-20  |  9KB  |  357 lines

  1. /*
  2.  * $Id: brcCurs.c,v 1.1 1991/09/20 19:10:24 mtranle Exp $
  3.  *
  4.  * Copyright IBM Corporation 1987,1990
  5.  *
  6.  * All Rights Reserved
  7.  *
  8.  * Permission to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted,
  10.  * provided that the above copyright notice appear in all copies and that 
  11.  * both that copyright notice and this permission notice appear in
  12.  * supporting documentation, and that the name of IBM not be
  13.  * used in advertising or publicity pertaining to distribution of the
  14.  * software without specific, written prior permission.
  15.  *
  16.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  18.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  19.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22.  * SOFTWARE.
  23.  *
  24. */
  25. /*
  26.  * PRPQ 5799-PFF (C) COPYRIGHT IBM CORPORATION 1987,1990
  27.  * LICENSED MATERIALS - PROPERTY OF IBM
  28.  * REFER TO COPYRIGHT INSTRUCTIONS FORM NUMBER G120-2083
  29.  */
  30. /*
  31.  *  Hardware interface routines for IBM 8514/A adapter for
  32.  *  X.11 server(s) on IBM equipment.
  33.  *
  34.  */
  35. /*
  36.  * Software Cursor implementation for 8514/A
  37.  *
  38.  * Depends on owning some off-screen memory in SAVELOC, etc #defined areas
  39.  */
  40.  
  41. #include "X.h"
  42. #include "Xmd.h"
  43. #include "miscstruct.h"
  44. #include "scrnintstr.h"
  45. #include "cursorstr.h"
  46. #include "pixmapstr.h"
  47. #include "colormapst.h"
  48.  
  49. #include "ibmScreen.h"
  50. #include "ibmColor.h"
  51.  
  52. #include "ppc.h"
  53.  
  54. #include "x8514.h"
  55.  
  56. #include "OScompiler.h"
  57. #include "ibmTrace.h"
  58. #include "maskbits.h"
  59.  
  60. void ibm8514ReplaceCursor();
  61.  
  62. extern ibmPerScreenInfo ibm8514ScreenInfoStruct ; /* From brcScrInfo.c */
  63.  
  64. #define CURBLIT( COL, X0, Y0, X1, Y1, LX, LY )    \
  65.     {                \
  66.        ibm8514CheckQueue( 8 ) ;    \
  67.     SETCOL1( COL ) ;        \
  68.     SETX0( X0 ) ;            \
  69.     SETY0( Y0 ) ;            \
  70.     SETX1( X1 ) ;            \
  71.     SETY1( Y1 ) ;            \
  72.     SETLX( LX - 1 ) ;        \
  73.     SETLY( LY - 1 ) ;        \
  74.     COMMAND( 0xC0F3 ) ;        \
  75.     }
  76.  
  77. /* Global Cursor State Semaphore */
  78. int ibm8514cursorSemaphore = 0 ;
  79.  
  80. static short int c_x = 0 ;
  81. static short int c_y = 0 ;
  82. static unsigned long int c_fg = 255 ;
  83. static unsigned long int c_bg = 0 ;
  84. static int active = FALSE ;
  85. static int cursor_not_displayed = FALSE ;
  86. static int curs_fore_r, curs_fore_g, curs_fore_b,
  87.        curs_back_r, curs_back_g, curs_back_b ;
  88. static int current_w = 32 ;
  89. static int current_h = 32 ;
  90.  
  91. static void
  92. ibm8514CBitblt( x0, y0, x1, y1 )
  93.      int x0, y0, x1, y1 ;
  94. {
  95.     /* TRACE( ( "ibm8514CBitblt:x0=%d,y0=%d,x1=%d,y1=%d\n",
  96.        x0, y0, x1, y1 ) ) ; */
  97.  
  98.     ibm8514ATRNotBusy ;
  99.     ibm8514CheckQueue( 4 ) ;
  100.     SETFN1( FNCPYRCT, FNREPLACE ) ;
  101.     SETX0( x0 ) ;
  102.     SETY0( y0 ) ;
  103.     SETX1( x1 ) ;
  104.  
  105.     ibm8514CheckQueue( 4 ) ;
  106.     SETY1( y1 ) ;
  107.     SETLX( current_w - 1 ) ;
  108.     SETLY( current_h - 1 ) ;
  109.     COMMAND( 0xC0F3 ) ;
  110.  
  111.     ibm8514CheckQueue( 1 ) ;
  112.     SETFN1( FNCOLOR1, FNREPLACE ) ;
  113.  
  114.     return ;
  115. }
  116.  
  117. void
  118. ibm8514RemoveCursor()
  119. {
  120.     /* TRACE(("ibm8514RemoveCursor()\n")) ; */
  121.     active = FALSE ;
  122.     ibm8514CBitblt( SAVELOCX, SAVELOCY,
  123.            c_x - ibm8514ScreenInfoStruct.ibm_CursorHotX,
  124.            c_y - ibm8514ScreenInfoStruct.ibm_CursorHotY ) ;
  125.     return ;
  126. }
  127.  
  128. static void
  129. ibm8514Overlay( x, y )
  130.      short x, y ;
  131. {
  132.     /*   TRACE(("ibm8514Overlay(%d,%d)\n",x,y)) ; */
  133.  
  134.     ibm8514ATRNotBusy ;
  135.     ibm8514CheckQueue( 5 ) ;
  136.     SETFN0( FNCOLOR0, FNNOP ) ;
  137.     SETFN1( FNCOLOR1, FNREPLACE ) ;
  138.     PLNRENBL( RPLANE0 ) ;
  139.     SETMODE( M_CPYRCT ) ;
  140.     SETYMAX( _8514_SCREENHEIGHT - 1 ) ;
  141.  
  142.     ibm8514ATRNotBusy ;
  143.     CURBLIT( c_fg, CUR1LOCX, CUR1LOCY, x, y, current_w, current_h ) ;
  144.     ibm8514ATRNotBusy ;
  145.     CURBLIT( c_bg, CUR0LOCX, CUR0LOCY, x, y, current_w, current_h ) ;
  146.  
  147.     ibm8514CheckQueue( 4 ) ;
  148.     SETYMAX( 1023 ) ;
  149.     PLNRENBL( RPLANES ) ;
  150.     SETFN0( FNCOLOR0, FNREPLACE ) ;
  151.     SETMODE( M_ONES ) ;
  152.  
  153.     return ;
  154. }
  155.  
  156. /***============================================================***/
  157.  
  158. void
  159. ibm8514CursorInit( index )
  160.      int index ;
  161. {
  162.     TRACE( ( "ibm8514CursorInit(%d)\n", index ) ) ;
  163.  
  164.     c_x = 0 ;
  165.     c_y = 0 ;
  166.     active = FALSE ;
  167.     ibm8514cursorSemaphore = 0 ;
  168.     cursor_not_displayed = FALSE ;
  169.     return ;
  170. }
  171.  
  172. /***============================================================***/
  173.  
  174. Bool
  175. ibm8514RealizeCursor( pScr, pCurs )
  176.      ScreenPtr    pScr ;
  177.      CursorPtr    pCurs ;
  178. {
  179.     unsigned long int tmpMask ;
  180.     unsigned long int endbits ;
  181.     unsigned long int *pFG, *pBG ;
  182.     unsigned long int *psrcImage, *psrcMask ;
  183.     int srcWidth ;
  184.     int srcHeight ;
  185.     int srcRealWidth ;
  186.  
  187.     TRACE( ( "ibm8514RealizeCursor(pScr=0x%x,pCurs=0x%x)\n", pScr, pCurs ) ) ;
  188.     if ( !( ( pCurs->devPriv[ pScr->myNum ] = (pointer) Xalloc( 256 ) ) ) )
  189.     {
  190.     ErrorF( "ibm8514RealizeCursor: can't malloc\n" ) ;
  191.     return FALSE ;
  192.     }
  193.     pFG = (unsigned long int *) pCurs->devPriv[pScr->myNum] ;
  194.     pBG = pFG + 32 ;        /* words */
  195.     bzero( (char *) pFG, 256 ) ;
  196.     psrcImage = (unsigned long int *) pCurs->bits->source ;
  197.     psrcMask = (unsigned long int *) pCurs->bits->mask ;
  198.     srcRealWidth = ( pCurs->bits->width + 31 ) / 32 ;
  199.  
  200.     srcWidth  = MIN( pCurs->bits->width, 32 ) ;
  201.     srcHeight = MIN( pCurs->bits->height, 32 ) ;
  202.  
  203.     endbits = ( srcWidth == 32 ) ? 0xFFFFFFFF : SCRLEFT( -1, (32-srcWidth) );
  204.  
  205.     while ( srcHeight-- )
  206.     {
  207.     tmpMask = *psrcMask &= endbits ;
  208.     *pFG++ = (*psrcImage) & tmpMask ;
  209.     *pBG++ = (~(*psrcImage)) & tmpMask ;
  210.     psrcImage += srcRealWidth ;
  211.     psrcMask  += srcRealWidth ;
  212.     }
  213.  
  214.     return TRUE ;
  215. }
  216.  
  217. /***============================================================***/
  218.  
  219. Bool
  220. ibm8514UnrealizeCursor( pScr, pCurs )
  221.      ScreenPtr pScr ;
  222.      CursorPtr pCurs ;
  223. {
  224.     TRACE( ( "ibm8514UnrealizeCursor(pScr=0x%x,pCurs=0x%x)\n",
  225.         pScr, pCurs ) ) ;
  226.  
  227.     Xfree( pCurs->devPriv[ pScr->myNum ] ) ;
  228.     pCurs->devPriv[ pScr->myNum ] = 0 ;
  229.     return TRUE ;
  230. }
  231.  
  232. void
  233. ibm8514ColorCursor( fg, bg )
  234.      unsigned long int fg, bg ;
  235. {
  236.     TRACE( ( "ibm8514ColorCursor(%d,%d)\n", fg, bg ) ) ;
  237.     if ( ( fg > 255 ) || ( bg > 255 ) )
  238.     {
  239.     ErrorF( "ibm8514ColorCursor: bad color value(s)(fg/bg)=(%d,%d)",
  240.            fg, bg ) ;
  241.     return ;
  242.     }
  243.     c_fg = fg ;
  244.     c_bg = bg ;
  245.  
  246.     return ;
  247. }
  248.  
  249. void
  250. ibm8514RecolorCursor( cmap )
  251.      ColormapPtr cmap ;
  252. {
  253.     c_fg = ibmFindColor( cmap, curs_fore_r, curs_fore_g, curs_fore_b ) ;
  254.     c_bg = ibmFindColor( cmap, curs_back_r, curs_back_g, curs_back_b ) ;
  255.     if ( active && ( !cursor_not_displayed ) )
  256.     {
  257.     ibm8514RemoveCursor();
  258.     cursor_not_displayed = TRUE;
  259.     ibm8514ReplaceCursor();
  260.     }
  261.     return ;
  262. }
  263.  
  264. /***============================================================***/
  265.  
  266. void
  267. ibm8514ShowCursor( x, y )
  268.      int x, y ;
  269. {
  270.     int xloc, yloc ;
  271.  
  272.     /* TRACE(("ibm8514ShowCursor(x=%d, y=%d)\n",x, y)) ; */
  273.     if ( active )
  274.     ibm8514RemoveCursor() ;
  275.  
  276.     xloc = ( c_x = x ) - ibm8514ScreenInfoStruct.ibm_CursorHotX ;
  277.     yloc = ( c_y = y ) - ibm8514ScreenInfoStruct.ibm_CursorHotY ;
  278.     ibm8514CBitblt( xloc, yloc, SAVELOCX, SAVELOCY ) ;
  279.     ibm8514Overlay( xloc, yloc ) ;
  280.     active = TRUE ;
  281.     return ;
  282. }
  283.  
  284. int
  285. ibm8514DisplayCursor( pScr, pCurs )
  286.      ScreenPtr pScr ;
  287.      CursorPtr pCurs ;
  288. {
  289.     int *curdef ;
  290.  
  291.     TRACE( ( "ibm8514DisplayCursor(pScr=0x%x,pCurs=0x%x)\n", pScr, pCurs ) ) ;
  292.  
  293.     if ( active )
  294.     ibm8514RemoveCursor() ;
  295.     curdef = (int *) pCurs->devPriv[ pScr->myNum] ;
  296.  
  297.     ibm8514ScreenInfoStruct.ibm_CursorHotX = pCurs->bits->xhot ;
  298.     ibm8514ScreenInfoStruct.ibm_CursorHotY = pCurs->bits->yhot ;
  299.     ibm8514ScreenInfoStruct.ibm_CurrentCursor = pCurs ;
  300.  
  301.     curs_fore_r = pCurs->foreRed ;
  302.     curs_fore_g = pCurs->foreGreen ;
  303.     curs_fore_b = pCurs->foreBlue ;
  304.     curs_back_r = pCurs->backRed ;
  305.     curs_back_g = pCurs->backGreen ;
  306.     curs_back_b = pCurs->backBlue ;
  307.  
  308.     ibm8514RecolorCursor(
  309.              ( (ppcScrnPrivPtr) pScr->devPrivate )->
  310.              InstalledColormap ) ;
  311.  
  312.     ibm8514AlignMonoImage( ibm8514ALLPLANES, GXcopy, C1X, C1Y,
  313.               CURD_X, CURD_Y, curdef ) ;
  314.     ibm8514AlignMonoImage( ibm8514ALLPLANES, GXcopy, C0X, C0Y,
  315.               CURD_X, CURD_Y, curdef + 32 ) ;
  316.  
  317.     current_w = MIN( pCurs->bits->width, CURD_X ) ;
  318.     current_h = MIN( pCurs->bits->height, CURD_Y ) ;
  319.  
  320.     ibm8514ShowCursor( c_x, c_y ) ;
  321.     return TRUE ;
  322. }
  323.  
  324. int
  325. ibm8514CheckCursor( x, y, lx, ly )
  326.      const int x, y, lx, ly ;
  327. {
  328.     /* check if the cursor is in this rectangle.  if so, remove and return TRUE
  329.        else return FALSE */
  330.  
  331.     if ( !ibm8514cursorSemaphore && active
  332.     && ( cursor_not_displayed == FALSE )
  333.     && !( ( x > ( c_x + current_w ) )
  334.          || ( y > ( c_y + current_h ) )
  335.          || ( ( x + lx ) < ( c_x - current_w ) )
  336.          || ( ( y + ly ) < ( c_y - current_h ) ) ) )
  337.     {
  338.     ibm8514RemoveCursor() ;
  339.     return cursor_not_displayed = TRUE ;
  340.     }
  341.     else
  342.     return FALSE ;
  343.     /*NOTREACHED*/
  344. }
  345.  
  346. void
  347. ibm8514ReplaceCursor()
  348. {
  349.     if ( cursor_not_displayed && !ibm8514cursorSemaphore )
  350.     {
  351.     ibm8514ShowCursor( c_x, c_y ) ;
  352.     cursor_not_displayed = FALSE ;
  353.     }
  354.  
  355.     return ;
  356. }
  357.