home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / screen / scrn02 / scrn1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-03-20  |  6.1 KB  |  226 lines

  1. /*
  2. *    TITLE    scrn1.c
  3. *    
  4. *    AUTHOR    Tim Spencer - Compuserve [73657,1400]
  5. *    DATE    March 13, 1987
  6. */
  7.  
  8. #include "dos.h"
  9. #include "video.h"
  10.  
  11.  
  12. /************************************************************************
  13.  scrn_init - Initializes the structure used to pass the screen buffer
  14.          address, offset(logical cursor), status port address, and
  15.          the boolean cga_card value to the assembler functions
  16.          that handle writing/reading directly to/from the screen.
  17.  
  18.    Example:  SCRN *scrn;     declare scrn to be type SCRN
  19.              scrn_init(&scrn);     initialize the structure scrn 
  20.  
  21.  Important:  A structure of type SCRN **must** be declared and initialized
  22.          as in this example before using any other scrn_xxx functions.
  23.          Otherwise, your computer will surely lock up.
  24. *************************************************************************/
  25. void scrn_init(scrn)
  26.   SCRN *scrn;        /* pointer to the structure */
  27.   {
  28.      int cols;        /* not used, but must be declared for vid_state() */
  29.      int mode;        /* current mode - mono, CO80, etc. */
  30.      int card;        /* card type...mono, cga, ega...  */     
  31.  
  32.      switch( (mode = vid_state(&cols)) ) { /* get current video mode...        */ 
  33.                       /* and make sure it's 80 columns */
  34.     case MONO_MODE:              
  35.     case BW80_MODE:
  36.     case CO80_MODE:
  37.         break;        /* no problem */
  38.  
  39.     default:        /* sorry, no graphics or 40 cols allowed */
  40.         vid_init(BW80_MODE); 
  41.         break;
  42.     }
  43.         
  44.      /* now set up screen buffer address and status port in SCRN structure */
  45.  
  46.      if ((card = vcard_type()) == MONO_ADAPTER) {
  47.     scrn->segment = MONO_SEG;
  48.     scrn->stat_port = MONO_BASE + CRT_STATUS;
  49.     scrn->cga_card = FALSE;
  50.     }
  51.      else
  52.     {
  53.     scrn->segment = COLOR_SEG;
  54.     scrn->stat_port = COLOR_BASE + CRT_STATUS;
  55.     scrn->cga_card = (card == CGA_ADAPTER) ? TRUE : FALSE ;
  56.     }
  57.                          
  58.      scrn->offset = 0;            /* set initial segment offset */
  59.      scrn->attrib = 7;            /* set initial attribute to normal */
  60.      vid_page(0);            /* force page zero */         
  61.   }
  62.            
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. /************************************************************************
  70.  scrn_pos - Sets the logical cursor position, or offset within the
  71.         screen buffer, to the specified row and column. The real
  72.         cursor is not affected.    
  73.  
  74.   Example:  int row = 10, col = 20;
  75.             scrn_pos(row, col, &scrn);   set to row 10, column 20 
  76. *************************************************************************/
  77.             
  78. void scrn_pos(row,col,scrn) 
  79.  int row, col;            
  80.  SCRN *scrn;
  81.  {
  82.     scrn->offset = (row * 80 + col) << 1 ;
  83.  }
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90. /************************************************************************
  91.  scrn_color - set the foreground and background color for direct screen
  92.           writes. Remains in effect until changed.     
  93.  
  94.    Example: scrn_color(BLUE, WHITE, &scrn);   set blue on white text 
  95.  
  96.  Foreground colors may be OR'd to the constants HIGHLIGHT and/or BLINK. 
  97.  For example, scrn_color(RED|BLINK|HIGHLIGHT, WHITE, scrn); sets blinking,
  98.  highlighted, red text on a white background. 
  99. *************************************************************************/
  100.  
  101. void scrn_color(fore, back, scrn)  
  102.  int fore, back;           
  103.  SCRN *scrn; 
  104.  {
  105.     scrn->attrib = ((back << 4) | fore);
  106.  }
  107.  
  108.  
  109.  
  110.  
  111.  
  112. /************************************************************************
  113.  scrn_attrib - Provided for easy setting of monochrome attributes. Can
  114.            be used to modify current color selection. 
  115.            
  116.    Example:  scrn_attrib(INVERSE, &scrn);
  117. *************************************************************************/  
  118.  
  119. void scrn_attrib(attribute, scrn)  
  120.  int attribute;            
  121.  SCRN *scrn;
  122.  {
  123.     scrn->attrib = attribute;
  124.  }     
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133. /************************************************************************ 
  134.  vid_state - get current video mode (see video.h for modes)
  135.  
  136.    Example: vid_mode = vstate(&cols);
  137.        
  138.  Puts current screen width into cols and returns current mode, i.e. CO80.
  139. *************************************************************************/
  140.  
  141. int vid_state(pcol)        
  142.  int *pcol ;            
  143.  {
  144.    union REGS inregs, outregs;
  145.  
  146.    inregs.h.ah = V_GET_MODE;        /* get mode function 15 */
  147.    int86(VIDEO_INT,&inregs,&outregs) ;
  148.    
  149.    *pcol = (outregs.h.ah);
  150.    
  151.    return(outregs.x.ax & 0xff);    
  152.  }
  153.  
  154.  
  155.  
  156.  
  157.  
  158. /************************************************************************ 
  159.  vid_init - select monitor mode (see video.h for modes)
  160.  
  161.     Example: vid_init(CO80);     set color/80 columns          
  162. *************************************************************************/
  163.  
  164. void vid_init(mode)        
  165.  int mode;
  166.  {
  167.      union REGS inregs, outregs;
  168.  
  169.      inregs.h.ah = V_SET_MODE;         /* set mode function (00h) */
  170.      inregs.h.al = (char)mode;      /* mode number goes in al */
  171.  
  172.      int86(VIDEO_INT, &inregs, &outregs);
  173.  
  174. }
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181. /************************************************************************
  182.  vid_page - sets the current page number, 0 through 7. 
  183.  
  184.    Example:  vid_page(0);    set page to zero
  185. *************************************************************************/
  186.  
  187. void vid_page(new_page)        /* set display page */
  188.  int new_page ;            /* new page number */
  189.  {
  190.    union REGS inregs, outregs;
  191.  
  192.    inregs.h.ah = V_SETPAGE;        /* select display page function */
  193.    inregs.h.al = (char)new_page & 0x07 ; /* force new page to be <= 7 */
  194.    int86(VIDEO_INT,&inregs,&outregs) ;
  195.  }
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. /************************************************************************
  203.  scrn_set_cga - sets the structure member 'cga_card' to false (zero) or
  204.         true (non-zero). If set to true, all subsequent direct screen 
  205.         reads and writes will check for horizontal retrace. If set to 
  206.         false, retrace checking will be bypassed. 
  207.  
  208.   Example:   #define TRUE = 1
  209.          #define FALSE = 0
  210.         .
  211.         .
  212.         .
  213.          scrn_set_cga(TRUE, &sc);      enables retrace checking
  214. *************************************************************************/
  215.  
  216. void scrn_set_cga(tf, scrn)
  217.  int tf;
  218.  SCRN *scrn;
  219.  {
  220.     if (tf)
  221.       scrn->cga_card = 1;
  222.     else
  223.       scrn->cga_card = 0;
  224.  }      
  225.         
  226.