home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / mpel / mpelUtil.c < prev    next >
C/C++ Source or Header  |  1990-01-26  |  8KB  |  263 lines

  1. /*
  2.  * Copyright IBM Corporation 1987,1988,1989
  3.  *
  4.  * All Rights Reserved
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted,
  8.  * provided that the above copyright notice appear in all copies and that 
  9.  * both that copyright notice and this permission notice appear in
  10.  * supporting documentation, and that the name of IBM not be
  11.  * used in advertising or publicity pertaining to distribution of the
  12.  * software without specific, written prior permission.
  13.  *
  14.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  15.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  16.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  17.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  18.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  19.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  20.  * SOFTWARE.
  21.  *
  22. */
  23. /***********************************************************
  24.         Copyright IBM Corporation 1987,1988
  25.  
  26.               All Rights Reserved
  27.  
  28. Permission to use, copy, modify, and distribute this software and its
  29. documentation for any purpose and without fee is hereby granted,
  30. provided that the above copyright notice appear in all copies and that
  31. both that copyright notice and this permission notice appear in
  32. supporting documentation, and that the name of IBM not be
  33. used in advertising or publicity pertaining to distribution of the
  34. software without specific, written prior permission.
  35.  
  36. IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  37. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  38. IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  39. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  40. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  41. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  42. SOFTWARE.
  43.  
  44. ******************************************************************/
  45.  
  46. /* $Header: /andrew/X11/r3src/release/server/ddx/ibm/mpel/RCS/mpelUtil.c,v 6.5 89/04/29 21:38:24 jeff Exp $ */
  47. /* $Source: /andrew/X11/r3src/release/server/ddx/ibm/mpel/RCS/mpelUtil.c,v $ */
  48.  
  49. #ifndef lint
  50. static char *rcsid = "$Header: /andrew/X11/r3src/release/server/ddx/ibm/mpel/RCS/mpelUtil.c,v 6.5 89/04/29 21:38:24 jeff Exp $";
  51. #endif
  52.  
  53. /*
  54.  * mpelutil.c
  55.  */
  56.  
  57. #define BADREAD
  58.  
  59. #include "X.h"
  60. #include "Xmd.h"
  61. #include "misc.h"
  62. #include "regionstr.h"
  63. #include "miscstruct.h"
  64.  
  65. #include "mpel.h"
  66. #include "mpelHdwr.h"
  67. #include "mpelFifo.h"
  68.  
  69. #include "ibmTrace.h"
  70.  
  71. #define DELAY_ADDR    0xf00080E0        /* IOCC delay location */
  72. #define DELAY(n)    { register int N = (n); \
  73.                 while (--N >= 0) \
  74.                     * (char *) DELAY_ADDR = 0xff;    }
  75.  
  76. #define RESET_INT_TMS_BIT (MPEL_PCR &= ~PCR_INTR_TMS)
  77. #define SET_INT_TMS_BIT (MPEL_PCR |= PCR_INTR_TMS)
  78.  
  79. #define MAXRETRY 500
  80.  
  81. int MPELNoOpData = 0;
  82.  
  83. mpelRectangle mpelDfltScissor = {
  84.     { 0, 0 }, { MPEL_WIDTH - 1, MPEL_HEIGHT - 1 }
  85. } ;
  86.  
  87. /***==================================================================***/
  88.  
  89. /*
  90.  * IDENTIFICATION: mpelicmd (copy from vtt8icmd)
  91.  * DESCRIPTIVE NAME: Issue an Adapte command for the Megapel
  92.  *             Virtual Display Driver (VDD)
  93.  * FUNCTION: Check for completion of any previous commands.
  94.  *         When done issue the requested command to the adapter
  95.  * END OF SPEC
  96.  */
  97.  
  98. void
  99. mpelicmd2( command_code, parameters, parm_count )
  100. unsigned short command_code;
  101. unsigned short parameters[];
  102. int   parm_count;
  103. {
  104.    int register i;
  105.    int retry = 0;
  106.    volatile unsigned short *COMM_Request_parm;
  107.    unsigned short reg;
  108.  
  109.     /*
  110.      * Issue COMM Area Command
  111.      */
  112.    MPEL_COMM_REQ = command_code;     /* Store request code into COMM area  */
  113.    COMM_Request_parm = MPEL_COMM_PARM_ADDR;
  114.    for ( i = 0 ; i < parm_count ; i++ )  /* Store parameters into COMM area */
  115.     COMM_Request_parm[i] = parameters[i];
  116.    RESET_INT_TMS_BIT;
  117.    SET_INT_TMS_BIT;                /* Interrupt adapter */
  118.  
  119.     /*
  120.      * check for interrupt pending: clear it.
  121.      */
  122.     retry = 0;
  123.     while (retry < MAXRETRY) {
  124.         reg = MPEL_PSR;
  125.         if (reg & PSR_INTR_PENDING) {
  126.             reg = MPEL_IPR;
  127.  
  128.             break;
  129.         }
  130.         DELAY(1000);
  131.         retry++;
  132.     }
  133.  
  134.     MPEL_COMM_REASON = 0x0000;
  135.     MPEL_COMM_REQ = 0x0000;
  136.     return;
  137. }
  138.  
  139. /*
  140.  * IDENTIFICATION: mpelicmd (copy from vtt8icmd)
  141.  * DESCRIPTIVE NAME: Issue an Adapter command for the Megapel
  142.  *             Virtual Display Driver (VDD)
  143.  * FUNCTION: Check for completion of any previous commands.
  144.  *         When done issue the requested command to the adapter
  145.  * END OF SPEC
  146.  */
  147.  
  148. void
  149. mpelicmd(command_code, parameters, parm_count)
  150.     unsigned short int command_code;
  151.     unsigned short int parameters[];
  152.     int       parm_count;
  153.  
  154. {
  155.     int        i;
  156.     int        retry = 0;
  157.     volatile unsigned short int *COMM_Request_parm;
  158.  
  159.     TRACE(("mpelicmd(0x%x,0x%x,%d)\n",command_code,parameters,parm_count));
  160.  
  161.     while(MPEL_COMM_REASON == 0) {   /* The previous command has not yet   */
  162.                             /* completed.               */
  163.     if( retry > MAXRETRY ) {     /* Adapter is taking too long         */
  164.         break;
  165.     }
  166.     DELAY( 1000 ) ;
  167.     retry++;             /* Another chance               */
  168.     }
  169.  
  170.     MPEL_COMM_REQ = command_code;     /* Store request code into COMM area  */
  171.     MPEL_COMM_REASON = 0;
  172.     COMM_Request_parm = MPEL_COMM_PARM_ADDR;
  173.     for(i = 0; i < parm_count ; i++)  /* Store parameters into COMM area    */
  174.     COMM_Request_parm[i] = parameters[i];
  175.     RESET_INT_TMS_BIT;
  176.     SET_INT_TMS_BIT;                /* Interrupt adapter           */
  177.     return;
  178. }
  179.  
  180. /***==================================================================***/
  181.  
  182. /*
  183.  * Poke the adapter -- execute some command (in this case
  184.  * reset blink, but it really doesn't matter which) and wait
  185.  * for it to complete.  Useful for making sure the adapter is
  186.  * alive and talking to us.
  187.  */
  188.  
  189. void
  190. mpelPoke()
  191. {
  192.     int    i;
  193.  
  194.     TRACE(("mpelPoke()\n"));
  195.  
  196.     MPEL_COMM_REQ= MPELCMD_RESET_BLINK;
  197.     MPEL_COMM_REASON= 0;
  198.     RESET_INT_TMS_BIT;
  199.     SET_INT_TMS_BIT;
  200.     for (i=1000000;MPEL_COMM_REQ!=MPELRSN_RESET_BLINK_DONE;i--) {
  201.     if (i<0) {
  202.         ErrorF("poke failed (%d)\n",(*(short *)0xf4c00904));
  203.         break;
  204.     }
  205.     }
  206.     return;
  207. }
  208.  
  209. /***==================================================================***/
  210.  
  211. void
  212. mpelInitPatterns()
  213. {
  214.     TRACE(("mpelInitPatterns()\n"));
  215.  
  216.     MPEL_STATE_LIST_PTR = mpelAddr(MPEL_PAT_TABLE);
  217.     MPEL_PAT_TABLE[0] = 4;
  218.     MPEL_PAT_TABLE[1] = 4;
  219.     *(volatile unsigned long int *)(MPEL_PAT_TABLE+2) = mpelAddr(MPEL_PAT1);
  220.     *(volatile unsigned long int *)(MPEL_PAT_TABLE+4) = mpelAddr(MPEL_PAT2);
  221.     *(volatile unsigned long int *)(MPEL_PAT_TABLE+6) = mpelAddr(MPEL_PAT3);
  222.     *(volatile unsigned long int *)(MPEL_PAT_TABLE+8) = mpelAddr(MPEL_PAT4);
  223.     return;
  224. }
  225.  
  226. /***==================================================================***/
  227.  
  228.     /*
  229.      * figure out how prect1 and prect2 overlap.
  230.      * returns:
  231.      *    rgnIN:    if prect1 contains prect2
  232.      *      rgnPART:    if prect1 and prect2 intersect
  233.      *            but prect1 does not contain prect2
  234.      *      rgnOUT:    if prect1 and prect2 do not intersect
  235.      */
  236.  
  237. int
  238. mpelRectIntersect(prect1, prect2)
  239.     register BoxPtr    prect1;
  240.     register BoxPtr     prect2;
  241. {
  242.  
  243.     TRACE(("mpelRectIntersect(0x%x,0x%x)\n",prect1,prect2));
  244.  
  245.     if ((prect2->x1>=prect1->x1)&&(prect2->x2<prect1->x2)&&
  246.     (prect2->y1>=prect1->y1)&&(prect2->y2<prect1->y2)) {
  247.     return rgnIN ;
  248.     }
  249.     if (prect1->x1 > prect2->x2)    /* rect1 right of rect2 */
  250.     return rgnOUT ;
  251.  
  252.     if (prect1->x2 < prect2->x1)    /* rect1 left of rect2  */
  253.     return rgnOUT ;
  254.  
  255.     if (prect1->y1 > prect2->y2)    /* rect1 below rect2 */
  256.     return rgnOUT ;
  257.  
  258.     if (prect1->y2 < prect2->y1)    /* rect1 above rect2 */
  259.     return rgnOUT ;
  260.  
  261.     return rgnPART ;
  262. }
  263.