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 / brcUtils.c < prev    next >
C/C++ Source or Header  |  1991-09-20  |  6KB  |  224 lines

  1. /*
  2.  * $Id: brcUtils.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. #include "X.h"
  37. #include "cursorstr.h"
  38. #include "scrnintstr.h"
  39. #include "miscstruct.h"
  40.  
  41. #include "OScompiler.h"
  42.  
  43. #include "x8514.h"
  44. #include "ibmTrace.h"
  45.  
  46. extern int ibm8514HeadInstalled ;
  47.  
  48. int mergexlate[16] ;
  49.  
  50. /******************************************************************************/
  51.  
  52. short
  53. ibm8514QueryHead()
  54. {
  55.  
  56.     switch ( ibm8514HeadInstalled = ( QCTRL & 0x0070 ) >> 4 )
  57.     {
  58.       case HEAD_COLOR1024:
  59.       case HEAD_COLOR640:
  60.     return PseudoColor ;
  61.       case HEAD_GRAY1024:
  62.       case HEAD_GRAY640:
  63.     return GrayScale ;
  64.       case 0 :            /* Temporarily 0 for the 19-inch grayscale
  65.                    tube */
  66.     return GrayScale ;
  67.       default:
  68.     ErrorF("ibm8514QueryHead: No known head attached. value = %d\n",
  69.            ibm8514HeadInstalled ) ;
  70.     return -1 ;        /* Ramdom Error Value */
  71.     }
  72.     /*NOTREACHED*/
  73. }
  74.  
  75. /******************************************************************************/
  76.  
  77. int
  78. ibm8514QueryPlanes()
  79. {
  80.     return ( QCTRL & 0x0080 ) ? 8 : 4 ;
  81. }
  82.  
  83. /******************************************************************************/
  84.  
  85. void
  86. ibm8514InitializeHardwareState()
  87. {
  88.  
  89.     TRACE( ( "ibm8514InitializeHardwareState()\n" ) ) ;
  90.  
  91.     ibm8514outw( ibm8514_MiscIO, 0 ) ; /* reset 'miscio' */
  92.     CRTCMODE( 0x0053 ) ;    /* reset on */
  93.     ibm8514SetVideoRegisters() ;
  94.     CRTCMODE( 0x0033 ) ;    /* reset off */
  95.  
  96.     ibm8514outw( ibm8514_MiscIO,    0x0005 ) ; /* set 'miscio' */
  97.     ibm8514outw( ibm8514_Control,   0x9000 ) ; /* reset brecon */
  98.     ibm8514outw( ibm8514_SecDecode, 0x5006 ) ; /* set config */
  99.     ibm8514outw( ibm8514_Control,   0x400F ) ; /* set constat */
  100.  
  101.     ibm8514ATRNotBusy ;
  102.     ibm8514CheckQueue( 7 ) ;
  103.     SETCOL0( 0 ) ;
  104.     SETCOL1( ibm8514ALLPLANES ) ;
  105.     PLNWENBL( ibm8514ALLPLANES ) ; /* enable all planes for write */
  106.     PLNRENBL( ibm8514ALLPLANES ) ; /* enable all planes for read */
  107.     SETFN0( FNCOLOR0, FNREPLACE ) ; /* my routines assume this is true */
  108.     SETFN1( FNCOLOR1, FNREPLACE ) ; /* my routines assume this is true */
  109.     SETMODE( M_ONES ) ;        /* assumed by this set of routines */
  110.  
  111.     ibm8514CheckQueue( 6 ) ;
  112.     SETPAT0( 0 ) ;        /* currently, I am not using the Pattern
  113.                    registers */
  114.     SETPAT1( 0 ) ;
  115.     SETXMIN( 0 ) ;        /* clip */
  116.     SETYMIN( 0 ) ;        /* clip */
  117.     SETXMAX( _8514_SCREEN_WIDTH - 1 ) ; /* clip */
  118.     SETYMAX( 1023 ) ;        /* clip */
  119.  
  120.     return ;
  121. }
  122.  
  123. int
  124. ibm8514ScreenInitHW( index )    /* returns number of planes */
  125.      int index ;
  126. {
  127.     int planes ;
  128.     extern void ibm8514osdInit() ; /* defined in brcOsd.c */
  129.  
  130.     TRACE( ( "ibm8514ScreenInitHW(index=%d)\n", index ) ) ;
  131.  
  132.     mergexlate[GXclear]         = 0x01 ;
  133.     mergexlate[GXand]         = 0x0C ;
  134.     mergexlate[GXandReverse]     = 0x0D ;
  135.     mergexlate[GXcopy]         = 0x07 ;
  136.     mergexlate[GXandInverted]     = 0x0E ;
  137.     mergexlate[GXnoop]         = 0x03 ;
  138.     mergexlate[GXxor]         = 0x05 ;
  139.     mergexlate[GXor]         = 0x0B ;
  140.     mergexlate[GXnor]         = 0x0F ;
  141.     mergexlate[GXequiv]     = 0x06 ;
  142.     mergexlate[GXinvert]     = 0x00 ;
  143.     mergexlate[GXorReverse]     = 0x0A ;
  144.     mergexlate[GXcopyInverted]     = 0x04 ;
  145.     mergexlate[GXorInverted]     = 0x09 ;
  146.     mergexlate[GXnand]         = 0x08 ;
  147.     mergexlate[GXset]         = 0x02 ;
  148.  
  149.     /* ******************** OS-DEPENDANT CALL ******************** */
  150.     ibm8514osdInit( index ) ;    /* defined in ibm8514osd.c */
  151.     /* Now is the first time the device registers may be referenced legally */
  152.     if ( !( planes = ibm8514QueryPlanes() ) || ( ibm8514QueryHead() < 0 ) )
  153.     return 0 ;
  154.  
  155.     ibm8514InitializeHardwareState() ;
  156.  
  157.     return planes ;
  158. }
  159.  
  160. #if defined(ATR) && defined(BSDrt)
  161.  
  162. /******************************************************************************/
  163. /*
  164.  *            WARNING!!!!!!!!!!!
  165.  *
  166.  * This routine does byte swapping!!  If you've never encountered this
  167.  * delightful consumer of your time, be careful!  And be glad you're dealing
  168.  * with Intel processors!!!
  169.  *
  170.  * Need to Byte-Swap for RT processor
  171.  */
  172. unsigned short
  173. ibm8514inw(addr)
  174.      unsigned int addr ;
  175. {
  176.     unsigned long int retval ;
  177.  
  178.     retval = *( (volatile unsigned long int *) ( addr | WORDADD ) ) ;
  179.     return (unsigned short) ( ((retval&0x0000ff00)>>8) | ((retval&0x000000ff)<<8) ) ;
  180. }
  181. #endif
  182.  
  183. /******************************************************************************/
  184.  
  185. #if defined(DEBUG) && !defined(NDEBUG)
  186.  
  187. #include <fcntl.h>
  188.  
  189. int
  190. ibm8514LoadPalette(fn)
  191.      char *fn ;
  192. {
  193.     int fh,i ;
  194.     unsigned char block[1024],c,r,g,b,*p ;
  195.     unsigned int red,green,blue ;
  196.  
  197.     fh = open(fn,O_RDONLY) ;
  198.     if (fh<0) { ErrorF("ibm8514LoadPalette: Error opening %s\n",fn) ; return(-1) ; }
  199.  
  200.     i = read(fh,block,1024) ;
  201.     if (i!=1024) {ErrorF("ibm8514LoadPalette: Error reading %s\n",fn) ;return(-1) ;}
  202.  
  203.     p = block ;
  204.     for (i=0 ; i<256 ; i++)
  205.     {
  206.     c = i ;
  207.     r = *p++ ;
  208.     b = *p++ ;        /* note that its RBG, unlike hardware,
  209.                    which is RGB */
  210.     g = *p++ ;
  211.     p++ ;            /* dummy */
  212.     red   = ((int)r) ;
  213.     green = ((int)g) ;
  214.     blue  = ((int)b) ;
  215.     red   <<=8 ;
  216.     green <<=8 ;        /* file contents are 8 bits per color */
  217.     blue  <<=8 ;
  218.     ibm8514SetColor(c,red,green,blue) ;
  219.     }
  220.     (void) close(fh) ;
  221.     return 0 ;
  222. }
  223. #endif
  224.