home *** CD-ROM | disk | FTP | other *** search
/ Shareware 1 2 the Maxx / sw_1.zip / sw_1 / PROGRAM / CBGRX100.ZIP / CONTRIB / LIBGRX / SRC / VGAREGS.H < prev    next >
Text File  |  1992-04-10  |  5KB  |  162 lines

  1. /** 
  2.  ** VGAREGS.H 
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. /*
  25.  * color plane operations
  26.  */
  27. #define VGA_FUNC_SET    0
  28. #define VGA_FUNC_AND    8
  29. #define VGA_FUNC_OR    16
  30. #define VGA_FUNC_XOR    24
  31.  
  32. /*
  33.  * Sequencer port and used register indices
  34.  */
  35. #define VGA_SEQUENCER_PORT    0x3c4
  36. #define VGA_SEQUENCER_DATA    0x3c5
  37.  
  38. #define VGA_WRT_PLANE_ENB_REG    2
  39.  
  40. /*
  41.  * Graphics controller port and used registers
  42.  */
  43. #define VGA_GR_CTRL_PORT    0x3ce
  44. #define VGA_GR_CTRL_DATA    0x3cf
  45.  
  46. #define VGA_SET_RESET_REG    0
  47. #define VGA_SET_RESET_ENB_REG    1
  48. #define VGA_COLOR_COMP_REG    2
  49. #define VGA_ROT_FN_SEL_REG    3
  50. #define VGA_RD_PLANE_SEL_REG    4
  51. #define VGA_MODE_REG        5
  52. #define VGA_MISC_REG        6
  53. #define VGA_COLOR_DONTC_REG    7
  54. #define VGA_BIT_MASK_REG    8
  55.  
  56. /*
  57.  * these are used from inline assembly...
  58.  */
  59. #ifdef __GNUC__
  60.   asm("L_VGA_GR_CTRL_PORT = 0x3ce");
  61.   asm("L_VGA_BIT_MASK_REG = 8");
  62.   asm("L_VGA_MODE_REG     = 5");
  63. #endif
  64.  
  65. #ifdef  __GNUC__
  66. #define _GetVGAModeMask() do {                        \
  67.     if(_GrAdapterType == GR_VGA) asm volatile(                 "\n\
  68.     movl    $L_VGA_GR_CTRL_PORT,%%edx                  \n\
  69.     movb    $L_VGA_MODE_REG,%%al                      \n\
  70.     outb    %%al,%%dx                          \n\
  71.     incl    %%edx                              \n\
  72.     inb    %%dx,%%al                          \n\
  73.     movb    %%al,%%ah                          \n\
  74.     andb    $0xfc,%%ah                          \n\
  75.     movb    $L_VGA_MODE_REG,%%al                      \n\
  76.     movl    %%eax,%0                           "\
  77.     : "=g" (_GrP4ModeReg)                        \
  78.     : /* NOTHING */                            \
  79.     : "dx", "ax"                            \
  80.     );                                    \
  81.     else { /* EGA */                            \
  82.     _GrP4ModeReg = VGA_MODE_REG;                    \
  83.     }                                    \
  84. } while(0)
  85.  
  86. /*
  87.  * set a VGA register
  88.  */
  89. #define __SET_VGA_REG__(port,reg,value) asm volatile(             "\n\
  90.     movl    %0,%%eax                          \n\
  91.     movl    %1,%%edx                          \n\
  92.     outw    %%ax,%%dx                           "\
  93.     : /* NOTHING */                            \
  94.     : "g" (((value) << 8) | (reg)), "g" (port)            \
  95.     : "dx", "ax"                            \
  96. )
  97. #endif  /* __GNUC__ */
  98.  
  99. #ifdef  __TURBOC__
  100. #define _GetVGAModeMask() do {                        \
  101.     if(_GrAdapterType == GR_VGA) {                    \
  102.     asm mov        dx,VGA_GR_CTRL_PORT;                \
  103.     asm mov        al,VGA_MODE_REG;                    \
  104.     asm out        dx,al;                        \
  105.     asm inc        dx;                            \
  106.     asm in        al,dx;                        \
  107.     _GrP4ModeReg = ((_AX & 0xfc) << 8) | VGA_MODE_REG;        \
  108.     }                                    \
  109.     else { /* EGA */                            \
  110.     _GrP4ModeReg = VGA_MODE_REG;                    \
  111.     }                                    \
  112. } while(0)
  113.  
  114. /*
  115.  * set a VGA register
  116.  */
  117. #define __SET_VGA_REG__(port,reg,value) do {                \
  118.     _AX = ((value) << 8) | (reg);                    \
  119.     _DX = (port);                            \
  120.     asm out dx,ax;                            \
  121. } while(0)
  122. #endif  /* __TURBOC__ */
  123.  
  124. /*
  125.  * Simple register settings
  126.  */
  127. #define _SetVGAWriteMode(mode) \
  128.     __SET_VGA_REG__(VGA_GR_CTRL_PORT,_GrP4ModeReg,mode)
  129.  
  130. #define _SetVGAWritePlane(plane) \
  131.     __SET_VGA_REG__(VGA_SEQUENCER_PORT,VGA_WRT_PLANE_ENB_REG,(1 << (plane)))
  132.  
  133. #define _SetVGAWriteAllPlanes() \
  134.     __SET_VGA_REG__(VGA_SEQUENCER_PORT,VGA_WRT_PLANE_ENB_REG,0x0f);
  135.  
  136. #define _SetVGAReadPlane(plane) \
  137.     __SET_VGA_REG__(VGA_GR_CTRL_PORT,VGA_RD_PLANE_SEL_REG,plane)
  138.  
  139. #define _SetVGASetResetPlanes(planes) \
  140.     __SET_VGA_REG__(VGA_GR_CTRL_PORT,VGA_SET_RESET_ENB_REG,planes)
  141.  
  142. #define _SetVGAColorFunction(func) \
  143.     __SET_VGA_REG__(VGA_GR_CTRL_PORT,VGA_ROT_FN_SEL_REG,func)
  144.  
  145. #define _SetVGAFillData(color) \
  146.     __SET_VGA_REG__(VGA_GR_CTRL_PORT,VGA_SET_RESET_REG,color)
  147.  
  148. #define _SetVGAWriteMask(mask) \
  149.     __SET_VGA_REG__(VGA_GR_CTRL_PORT,VGA_BIT_MASK_REG,mask)
  150.  
  151. /*
  152.  * Somewhat more complex register settings
  153.  */
  154. #define _SetVideoColorOper(oper) \
  155.     __SET_VGA_REG__(VGA_GR_CTRL_PORT,_GrP4WriteOps[oper],0)
  156.  
  157. #define _SetVideoColor(color,oper) do {                    \
  158.     _SetVideoColorOper(oper);                        \
  159.     _SetVGAFillData(color);                        \
  160. } while(0)
  161.  
  162.