home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / INTERNET / UPC2S1.ZIP / SCRSIZE.C < prev    next >
C/C++ Source or Header  |  1993-05-02  |  5KB  |  136 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    s c r s i z e .  c                                              */
  3. /*                                                                    */
  4. /*    Report screen size under MS-DOS                                 */
  5. /*                                                                    */
  6. /*    Copyright (c) 1992 by Kendra Electronic Wonderworks.            */
  7. /*    All rights reserved except those explicitly granted by          */
  8. /*    the UUPC/extended license.                                      */
  9. /*--------------------------------------------------------------------*/
  10.  
  11. /*
  12.  *    $Id: SCRSIZE.C 1.6 1993/05/03 02:41:57 ahd Exp $
  13.  *
  14.  *    $Log: SCRSIZE.C $
  15.  *     Revision 1.6  1993/05/03  02:41:57  ahd
  16.  *     Trap funky screen size on pre-DOS 4.0 boxes (poor babies...)
  17.  *
  18.  *     Revision 1.5  1992/12/30  05:27:11  plummer
  19.  *     MS C compile fixes
  20.  *
  21.  * Revision 1.4  1992/12/18  12:05:57  ahd
  22.  * Fix query for ANSI sys
  23.  *
  24.  * Revision 1.3  1992/12/11  12:45:11  ahd
  25.  * Use BIOS values if no ANSI driver
  26.  *
  27.  * Revision 1.2  1992/11/29  22:09:10  ahd
  28.  * Add stdlib.h for _osmajor under MSC
  29.  *
  30.  * Revision 1.1  1992/11/27  14:36:10  ahd
  31.  * Initial revision
  32.  *
  33.  */
  34.  
  35. /*--------------------------------------------------------------------*/
  36. /*                        System include files                        */
  37. /*--------------------------------------------------------------------*/
  38.  
  39. #include <stdio.h>
  40. #include <stdlib.h>
  41. #include <dos.h>
  42.  
  43. /*--------------------------------------------------------------------*/
  44. /*                    UUPC/extended include files                     */
  45. /*--------------------------------------------------------------------*/
  46.  
  47. #include "lib.h"
  48. #include "scrsize.h"
  49.  
  50. /*--------------------------------------------------------------------*/
  51. /*    s c r s i z e                                                   */
  52. /*                                                                    */
  53. /*    Return screen size under MS-DOS 4.0 and 5.0                     */
  54. /*--------------------------------------------------------------------*/
  55.  
  56. short scrsize( void )
  57. {
  58.  
  59. #ifdef __TURBOC__
  60.    static unsigned char far *bios_rows = MK_FP( 0x0040, 0x0084 );
  61. /* static unsigned char far *bios_cols = MK_FP( 0x40, 0x4a ); */
  62. #else
  63.    static unsigned char far *bios_rows = 0x0484;
  64. #endif
  65.  
  66.    static boolean error = FALSE;
  67.    static short default_rows = 0;
  68.  
  69.    typedef struct _DISPLAYMODE   /* Page 310 MS-DOS 5.0 PGMR Reference */
  70.    {
  71.       char  dmInfoLevel;
  72.       char  dmReserved1;
  73.       short dmDataLength;
  74.       short dmFlags;
  75.       char  dmMode;
  76.       char  dmReserved2;
  77.       short dmColors;
  78.       short dmWidth;
  79.       short dmLength;
  80.       short dmColumns;
  81.       short dmRows;
  82.  
  83.    } DISPLAYMODE;
  84.  
  85.    DISPLAYMODE info;
  86.  
  87.    union REGS regs;
  88.  
  89. /*--------------------------------------------------------------------*/
  90. /*            If an old version of DOS, return stock size             */
  91. /*--------------------------------------------------------------------*/
  92.  
  93.    if ((*bios_rows < 20 ) || (*bios_rows > 99)) /* Sanity check   */
  94.       default_rows = 24;
  95.  
  96.    if ((_osmajor < 4) || error )
  97.       return (short) (default_rows ? default_rows : *bios_rows);
  98.                                  /* Faster, but not well documented  */
  99.  
  100. /*--------------------------------------------------------------------*/
  101. /*             Fill in information to perform processing              */
  102. /*--------------------------------------------------------------------*/
  103.  
  104.    info.dmInfoLevel   = 0;       /* Magic number in book          */
  105.    info.dmReserved1   = 0;       /* Magic number in book          */
  106.    info.dmReserved2   = 0;       /* Magic number in book          */
  107.    info.dmDataLength  = 14;      /* Magic number in book          */
  108.  
  109.    regs.x.bx = 0x0001;           /* STDOUT file handle            */
  110.    regs.h.ch = 0x03;             /* Screen device category        */
  111.    regs.h.cl = 0x7f;             /* Get display mode              */
  112.    regs.x.ax = 0x440c;           /* Video Status                  */
  113.    regs.x.dx = (short) &info;    /* Address of structure          */
  114.  
  115.    intdos(®s, ®s );
  116.  
  117. /*--------------------------------------------------------------------*/
  118. /*    If we have an error, set up to use the BIOS information (or     */
  119. /*    a fixed default) on future calls.  Otherwise, return the        */
  120. /*    ANSI supplied value.                                            */
  121. /*--------------------------------------------------------------------*/
  122.  
  123.    if ( regs.x.cflag )
  124.    {
  125.       printmsg(2,"DOS error %d retrieving screen size, using BIOS value %d",
  126.                   (int) regs.x.ax,
  127.                   (short) (default_rows ? default_rows : *bios_rows ));
  128.       error = TRUE;
  129.       return (short) (default_rows ? default_rows : *bios_rows);
  130.                                  /* Faster, but not well documented  */
  131.    }
  132.    else
  133.       return info.dmRows;
  134.  
  135. } /* scrsize */
  136.