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 / brcMono.c < prev    next >
C/C++ Source or Header  |  1991-09-30  |  13KB  |  489 lines

  1. /*
  2.  * $Id: brcMono.c,v 1.2 1991/10/01 02:32:04 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. /* MONO-
  37.    This file is here to do the sundry Monochrome ops on the 8514.  You
  38.    may wish to read or write a plane or take a depth - 1 image and use
  39.    it to fill Foreground and Background.
  40.  
  41.    Monochrome ops to the 8514 are a bear ( in terms of cycles ) when the
  42.    target is not a 4-ple, so these routines plan on you drawing to a 4-ple
  43.    target ( off-screen if necessary ) and blitting to the final destination
  44.    if necessary.
  45. */
  46.  
  47. #include "X.h"
  48. #include "Xmd.h"
  49. #include "os.h"
  50.  
  51. #include "OScompiler.h"
  52.  
  53. #include "x8514.h"
  54.  
  55. #include "ibmTrace.h"
  56.  
  57. extern int mergexlate[] ;
  58. extern int ibm8514cursorSemaphore ;
  59.  
  60. /* I/O port type is 4 bytes for 6152 but only 2 for i386 !! */
  61. #if defined(ATRIO)
  62. /*
  63.  * Transmogrify: To change or alter greatly and often with
  64.  *    grotesque or humorous effect.
  65.  * ( Websters Ninth New Collegiate Dictionary )
  66.  */
  67. #define transmogrify( byte ) \
  68. ( ( ( byte | ( ( ( unsigned short int ) byte ) << 4 ) ) & ~ 0xF0 ) << 1 )
  69.  
  70. static void
  71. blockouttransmogrifiedw( values, n )
  72.      unsigned char *values ;
  73.      int n ;
  74. {
  75.     unsigned char tmp ;
  76.     volatile unsigned long int * const ptr =
  77.     (volatile unsigned long int *) ( VARDATA | WORDADD ) ;
  78.  
  79.     while ( n-- )
  80.     {
  81.     tmp = *values++ ;
  82.     *ptr = (unsigned long int) transmogrify( tmp ) ;
  83.     }
  84.     return ;
  85. }
  86. #else /* Not "ATRIO" */
  87. # if defined(i386) && defined(PCIO )
  88. #  if !defined(USE_PORTABLE_BLOCKOUTTRANSMOGRIFIEDW)
  89.  
  90. #   if defined(__GNUC__) && defined(i386)
  91. /* We don't really need to do the ibm8514CheckQueue(1). It just
  92.  * slow down the output process.
  93.  */
  94. #define blockouttransmogrifiedw( ptr, n )\
  95. ({ void * __ptr = (ptr);        \
  96.    int    __n   = (n);            \
  97.    __asm volatile (            \
  98.     "jcxz    . + 22 /* done */    \n\
  99.     movw    $0xE2E8, %%edx        \n\
  100. /* loop1:    */            \n\
  101.     lodsb                \n\
  102.     shll    $4, %%eax        \n\
  103.     shrb    $4, %%al        \n\
  104.     addl    %%eax, %%eax        \n\
  105.     xchgb    %%ah, %%al        \n\
  106.     outw    (%%dx)            \n\
  107.     loop    . - 13 /* loop1 */    \n\
  108. /* done:    */"            \
  109.     : "=S" (__ptr), "c=" (__n)    \
  110.     : "0"  (__ptr), "1"  (__n)    \
  111.     : "ax", "dx" );            \
  112.  })
  113.  
  114. #   else /* not __GNUC__ */
  115.  
  116. extern void blockouttransmogrifiedw() ;    /* defined in blkout.s */
  117.  
  118. #   endif /* not __GNUC__ */
  119. #  else /* USE_PORTABLE_BLOCKOUTTRANSMOGRIFIEDW */
  120.  
  121. #define transmogrify( byte ) \
  122. ( ( ( byte >> 3 ) | ( ( (unsigned short int) byte ) << 9 ) ) & 0x1E1E )
  123.  
  124. static void
  125. blockouttransmogrifiedw( values, n )
  126.      unsigned char *values ;
  127.      int n ;
  128. {
  129.     unsigned char tmp ;
  130.  
  131.     while ( n-- )
  132.     {
  133.     tmp = *values++ ;
  134.     /* XXX make this smarter if we can */
  135.     ibm8514CheckQueue( 1 ) ;
  136.     outw( VARDATA, transmogrify( tmp ) ) ;
  137.     }
  138.     return ;
  139. }
  140. #  endif /* USE_PORTABLE_BLOCKOUTTRANSMOGRIFIEDW */
  141. # else /* Not "PCIO" */
  142.     ******** ERROR ********
  143. # endif /* Not "PCIO" */
  144. #endif /* Not "ATRIO" */
  145.  
  146. /* Used by cursor & FillSpans */
  147. void
  148. ibm8514AlignMonoImage( planes, merge, x, y, lx, ly, data )
  149.      unsigned long int planes ;
  150.      int merge ;
  151.      short x, y, lx, ly;
  152.      unsigned char *data ;
  153. {
  154.     /*WARNING WARNING WARNING this routine merges 1's to requested planes and
  155.      * 0's ro requested planes, BUT ALIGNS X TO BE A MULTIPLE OF FOUR!!!
  156.      *
  157.      * Use ibm8514StageMono and Blit to get monochrome images elsewhere
  158.      */
  159.     short width ;
  160.     unsigned short alu = mergexlate[merge];
  161.     int CursorIsSaved ;
  162.  
  163.     TRACE(("ibm8514AlignMonoImage(planes=x%x,merge=x%x,x=x%x,y=x%x,lx=x%x,ly=x%x,data=x%x)\n",
  164.        planes, merge, x, y, lx, ly, data ) ) ;
  165.  
  166.     if ( ( lx <= 0 ) || ( ly <= 0 ) )
  167.     return ;
  168.  
  169.     CursorIsSaved = (!ibm8514cursorSemaphore
  170.              && ibm8514CheckCursor( x, y, lx, ly )) ;
  171.  
  172.     ibm8514ATRNotBusy ;
  173.     ibm8514CheckQueue( 4 ) ;
  174.     PLNWENBL( planes ) ;
  175.     SETMODE( M_VAR ) ;
  176.     SETFN0( FNCOLOR0, alu ) ;
  177.     SETFN1( FNCOLOR1, alu ) ;
  178.     x &= ~ 03 ;            /* alignment happens here */
  179.     ibm8514CheckQueue( 4 ) ;
  180.     SETX0( x ) ;
  181.     SETY0( y ) ;
  182.                 /* measured in BITS - clip will discard
  183.                    excess */
  184.     width = ( lx + 0x1F ) >> 5 ;
  185.     SETLX( ( width << 5 ) - 1 ) ;
  186.     SETLY( ly - 1 ) ;
  187.  
  188.     ibm8514CheckQueue( 4 ) ;
  189.     SETCOL1( 255 ) ;
  190.     SETCOL0( 0 ) ;
  191.     SETXMAX( x + lx - 1 ) ;
  192.     COMMAND( ibm8514WriteXYData ) ;
  193.     blockouttransmogrifiedw( data, width * ly * 4 ) ;
  194.  
  195.     ibm8514ClearQueue( 5 ) ;
  196.     SETMODE( M_ONES ) ;
  197.     SETFN1( FNCOLOR1, FNREPLACE ) ;
  198.     SETFN0( FNCOLOR0, FNREPLACE ) ;
  199.     PLNWENBL( ibm8514ALLPLANES ) ;
  200.     SETXMAX( _8514_SCREEN_WIDTH - 1 ) ;
  201.  
  202.     if ( CursorIsSaved )
  203.     ibm8514ReplaceCursor() ;
  204.     return ;
  205. }
  206.  
  207. /* Used By Stipple */
  208. void
  209. ibm8514StageMono( lx, ly, data )
  210.      short lx, ly ;
  211.      unsigned char *data ;
  212. {
  213.     int CursorIsSaved;
  214.     short x, y;
  215.     unsigned short width;
  216.     unsigned short alu = mergexlate[GXcopy];
  217.  
  218.     TRACE(("ibm8514StageMono(lx=x%x,ly=x%x,data=x%x)\n",lx,ly,data));
  219.  
  220.     if ( ( lx <= 0 ) || ( ly <= 0 ) )
  221.     return ;
  222.     /*
  223.      * ibm8514AlignMonoImage( MONO_STAGE_WPLANE, GXcopy, MONO_STAGE_X, MONO_STAGE_Y, 
  224.      *              lx, ly, data ) ;
  225.      */
  226.     CursorIsSaved = (!ibm8514cursorSemaphore
  227.              && ibm8514CheckCursor( x, y, lx, ly )) ;
  228.  
  229.     x = MONO_STAGE_X;
  230.     y = MONO_STAGE_Y;
  231.  
  232.     ibm8514ATRNotBusy ;
  233.     ibm8514CheckQueue( 4 ) ;
  234.     PLNWENBL( MONO_STAGE_WPLANE ) ;
  235.     SETMODE( M_VAR ) ;
  236.     SETFN0( FNCOLOR0, alu ) ;
  237.     SETFN1( FNCOLOR1, alu ) ;
  238.  
  239.     ibm8514CheckQueue( 4 ) ;
  240.     SETX0( x ) ;
  241.     SETY0( y ) ;
  242.                 /* measured in BITS - clip will discard
  243.                    excess */
  244.     width = ( lx + 0x1F ) >> 5 ;
  245.     SETLX( ( width << 5 ) - 1 ) ;
  246.     SETLY( ly - 1 ) ;
  247.  
  248.     ibm8514CheckQueue( 4 ) ;
  249.     SETCOL1( 255 ) ;
  250.     SETCOL0( 0 ) ;
  251.     SETXMAX( x + lx - 1 ) ;
  252.     COMMAND( ibm8514WriteXYData ) ;
  253.     blockouttransmogrifiedw( data, width * ly * 4 ) ;
  254.  
  255.     ibm8514ClearQueue( 5 ) ;
  256.     SETMODE( M_ONES ) ;
  257.     SETFN1( FNCOLOR1, FNREPLACE ) ;
  258.     SETFN0( FNCOLOR0, FNREPLACE ) ;
  259.     PLNWENBL( ibm8514ALLPLANES ) ;
  260.     SETXMAX( _8514_SCREEN_WIDTH - 1 ) ;
  261.  
  262.     if ( CursorIsSaved )
  263.     ibm8514ReplaceCursor() ;
  264.     return ;
  265. }
  266.  
  267. /* Not Used ??? */
  268. void
  269. ibm8514FillMonoImage( planes, fg, bg, merge, x, y, lx, ly, data )
  270.      unsigned long int planes, fg, bg ;
  271.      int merge;
  272.      int x, y, lx, ly ;
  273.      unsigned char *data ;
  274. {
  275.     int count ;
  276.     int blocksize, CursorIsSaved ;
  277.  
  278.     TRACE(("ibm8514FillMonoImage(planes=x%x,fg=x%x,bg=x%x,merge=x%x,x=x%x,y=x%x,lx=x%x,ly=x%x,data=x%x)\n",
  279.        planes, fg, bg, merge, x, y, lx, ly, data ) ) ;
  280.  
  281.     if ( ( lx <= 0 ) || ( ly <= 0 ) )
  282.     return ;
  283.  
  284.     CursorIsSaved = (!ibm8514cursorSemaphore &&
  285.              ibm8514CheckCursor( x, y, lx, ly )) ;
  286.     ibm8514cursorSemaphore++ ;
  287.  
  288.     blocksize = ( lx + 3 ) * MONO_STAGE_SIZE ;
  289.     count = ( ( ly + MONO_STAGE_SIZE - 1 ) / MONO_STAGE_SIZE ) - 1 ;
  290.     while ( count-- )
  291.     {
  292.     ibm8514StageMono( lx, MONO_STAGE_SIZE, data ) ;
  293.     ibm8514BlitFGBG( MONO_STAGE_RPLANE, planes, fg, bg, merge, 
  294.             MONO_STAGE_X, MONO_STAGE_Y, 
  295.             x, y, lx, MONO_STAGE_SIZE ) ;
  296.     data += blocksize ;
  297.     y += MONO_STAGE_SIZE ;
  298.     ly -= MONO_STAGE_SIZE ;
  299.     }
  300.     if ( ly )
  301.     {
  302.     ibm8514StageMono( lx, ly, data ) ;
  303.     ibm8514BlitFGBG( MONO_STAGE_RPLANE, planes, fg, bg, merge, 
  304.             MONO_STAGE_X, MONO_STAGE_Y, 
  305.             x, y, lx, ly ) ;
  306.     }
  307.     if ( !--ibm8514cursorSemaphore && CursorIsSaved )
  308.     ibm8514ReplaceCursor() ;
  309.     return ;
  310. }
  311.  
  312. /* Not Used ?? */
  313. void
  314. ibm8514DrawMonoByteImage( data, x, y, lx, ly, fg, merge, planes )
  315.      unsigned char *data ;
  316.      unsigned long int fg ;
  317.      short x, y, lx, ly ;
  318.      int merge ;
  319.      unsigned long int planes ;
  320. {
  321.     /*WARNING WARNING WARNING this routine merges 1's to requested planes and
  322.      * 0's ro requested planes, BUT ALIGNS X TO BE A MULTIPLE OF FOUR!!!
  323.      *
  324.      * Use ibm8514StageMono and Blit to get monochrome images elsewhere
  325.      */
  326.     int width ;
  327.     int CursorIsSaved ;
  328.  
  329.     TRACE(("ibm8514DrawMonoImage(planes=x%x,merge=x%x,x=x%x,y=x%x,lx=x%x,ly=x%x,data=x%x)\n",
  330.        planes, merge, x, y, lx, ly, data ) ) ;
  331.  
  332.     if ( ( lx <= 0 ) || ( ly <= 0 ) )
  333.     return ;
  334.     CursorIsSaved = (!ibm8514cursorSemaphore
  335.              && ibm8514CheckCursor( x, y, lx, ly )) ;
  336.     ibm8514ATRNotBusy ;
  337.     ibm8514CheckQueue( 5 ) ;
  338.     PLNWENBL( planes ) ;
  339.     SETMODE( M_VAR ) ;
  340.     SETCOL1( fg ) ;
  341.     SETFN0( FNCOLOR0, FNNOP ) ;
  342.     SETFN1( FNCOLOR1, mergexlate[merge] ) ;
  343.     x &= ~ 03 ;            /* alignment happens here */
  344.  
  345.     ibm8514CheckQueue( 6 ) ;
  346.     SETX0( x ) ;
  347.     SETY0( y ) ;
  348.     width = ( lx + 7 ) >> 3 ;
  349.     SETLX( ( width << 3 ) - 1 ) ;
  350.                 /* measured in BITS - clip will discard
  351.                    excess */
  352.     SETLY( ly - 1 ) ;
  353.     SETXMAX( x + lx - 1 ) ;
  354.     COMMAND( ibm8514WriteXYData ) ;
  355.  
  356.     blockouttransmogrifiedw( data, width * ly * 4 ) ;
  357.  
  358.     ibm8514ClearQueue( 5 ) ;
  359.     SETMODE( M_ONES ) ;
  360.     SETFN1( FNCOLOR1, FNREPLACE ) ;
  361.     SETFN0( FNCOLOR0, FNREPLACE ) ;
  362.     PLNWENBL( ibm8514ALLPLANES ) ;
  363.     SETXMAX( _8514_SCREEN_WIDTH - 1 ) ;
  364.  
  365.     if ( CursorIsSaved )
  366.     ibm8514ReplaceCursor() ;
  367.     return ;
  368. }
  369.  
  370. /* Used For Stipples */
  371. void
  372. ibm8514DrawMonoImage( data, x, y, lx, ly, fg, merge, planes )
  373.      unsigned char *data ;
  374.      short x, y, lx, ly ;
  375.      unsigned long int fg ;
  376.      int merge ;
  377.      unsigned long int planes ;
  378. {
  379.     /*WARNING WARNING WARNING this routine
  380.      * ALIGNS X TO BE A MULTIPLE OF FOUR!!!
  381.      *
  382.      * Use ibm8514StageMono and Blit to get monochrome images elsewhere
  383.      */
  384.     int width ;
  385.     int CursorIsSaved ;
  386.  
  387.     TRACE( ( "ibm8514DrawMonoImage( planes=x%x, merge=x%x, x=x%x, y=x%x, lx=x%x, ly=x%x, data=x%x )\n", 
  388.         planes, merge, x, y, lx, ly, data ) ) ;
  389.  
  390.     if ( ( lx <= 0 ) || ( ly <= 0 ) )
  391.     return ;
  392.  
  393.     CursorIsSaved = (!ibm8514cursorSemaphore &&
  394.              ibm8514CheckCursor( x, y, lx, ly )) ;
  395.  
  396.     ibm8514ATRNotBusy ;
  397.     ibm8514CheckQueue( 8 ) ;
  398.     PLNWENBL( planes ) ;
  399.     SETMODE( M_VAR ) ;
  400.     SETCOL1( fg ) ;
  401.     SETFN0( FNCOLOR0, FNNOP ) ;
  402.     SETFN1( FNCOLOR1, mergexlate[merge] ) ;
  403.     x &= ~ 03 ;            /* alignment happens here */
  404.  
  405.     SETX0( x ) ;
  406.     SETY0( y ) ;
  407.                 /* measured in BITS - clip will discard
  408.                    excess */
  409.     width = ( lx + 0x1F ) >> 5 ;
  410.     SETLX( ( 32*width ) - 1 ) ;
  411.  
  412.     ibm8514CheckQueue( 3 ) ;
  413.     SETLY( ly - 1 ) ;
  414.     SETXMAX( x + lx - 1 ) ;
  415.     COMMAND( ibm8514WriteXYData ) ;
  416.     blockouttransmogrifiedw( data, width*ly*4 ) ;
  417.  
  418.     ibm8514ClearQueue( 5 ) ;
  419.     SETMODE( M_ONES ) ;
  420.     SETFN1( FNCOLOR1, FNREPLACE ) ;
  421.     SETFN0( FNCOLOR0, FNREPLACE ) ;
  422.     PLNWENBL( ibm8514ALLPLANES ) ;
  423.     SETXMAX( _8514_SCREEN_WIDTH - 1 ) ;
  424.  
  425.     if ( CursorIsSaved )
  426.     ibm8514ReplaceCursor() ;
  427.  
  428.     return ;
  429. }
  430.  
  431. /* Used By "Glyph-Blit" */
  432. void
  433. ibm8514ByteAlignMonoImage( planes, merge, x, y, lx, ly, data )
  434.      unsigned long int planes ;
  435.      int merge;
  436.      short x, y, lx, ly ;
  437.      unsigned char *data ;
  438. {
  439.     /*WARNING WARNING WARNING this routine merges 1's to requested planes and
  440.      * 0's ro requested planes, BUT ALIGNS X TO BE A MULTIPLE OF FOUR!!!
  441.      *
  442.      * Use ibm8514StageMono and Blit to get monochrome images elsewhere
  443.      */
  444.     int CursorIsSaved ;
  445.     short width ;
  446.     short alu = mergexlate[merge];
  447.  
  448.     TRACE( ( "ibm8514ByteAlignMonoImage( planes=x%x, merge=x%x, x=x%x, y=x%x, lx=x%x, ly=x%x, data=x%x )\n", 
  449.         planes, merge, x, y, lx, ly, data ) ) ;
  450.  
  451.     if ( ( lx <= 0 ) || ( ly <= 0 ) )
  452.     return ;
  453.  
  454.     CursorIsSaved = !ibm8514cursorSemaphore && ibm8514CheckCursor( x, y, lx, ly ) ;
  455.  
  456.     ibm8514ATRNotBusy ;
  457.     ibm8514CheckQueue( 8 ) ;
  458.     PLNWENBL( planes ) ;
  459.     SETMODE( M_VAR ) ;
  460.     SETFN0( FNCOLOR0, alu ) ;
  461.     SETFN1( FNCOLOR1, alu ) ;
  462.     x &= ~ 03 ;            /* alignment happens here */
  463.  
  464.     SETX0( x ) ;
  465.     SETY0( y ) ;
  466.     width =  ( lx + 7 ) >> 3 ;
  467.     SETLX( ( 8*width ) - 1 ) ;    /* measured in BITS */
  468.     SETLY( ly - 1 ) ;
  469.  
  470.     ibm8514CheckQueue( 4 ) ;
  471.     SETCOL1( 255 ) ;
  472.     SETCOL0( 0 ) ;
  473.     SETXMAX( x + lx - 1 ) ;
  474.     COMMAND( ibm8514WriteXYData ) ;
  475.     blockouttransmogrifiedw( data, width * ly ) ;
  476.  
  477.     ibm8514ClearQueue( 5 ) ;
  478.     SETMODE( M_ONES ) ;
  479.     SETFN1( FNCOLOR1, FNREPLACE ) ;
  480.     SETFN0( FNCOLOR0, FNREPLACE ) ;
  481.     PLNWENBL( ibm8514ALLPLANES ) ;
  482.     SETXMAX( _8514_SCREEN_WIDTH - 1 ) ;
  483.  
  484.     if ( CursorIsSaved )
  485.     ibm8514ReplaceCursor() ;
  486.  
  487.     return ;
  488. }
  489.