home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / learn / sysinfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-12-03  |  3.0 KB  |  77 lines

  1. /* SYSINFO.C illustrates miscellaneous DOS and BIOS status functions
  2.  * including:
  3.  *      _dos_getdrive       _dos_setdrive       _dos_getdiskfree
  4.  *      _bios_memsize       _bios_equiplist     _bios_printer
  5.  *
  6.  * See DISK.C for another example of _dos_getdiskfree.
  7.  *
  8.  * Also illustrated:
  9.  *      union               bitfield struct
  10.  */
  11.  
  12. #include <dos.h>
  13. #include <bios.h>
  14. #include <conio.h>
  15. #include <stdio.h>
  16. #define LPT1 0
  17.  
  18. main()
  19. {
  20.     struct diskfree_t drvinfo;
  21.     unsigned drive, drivecount, memory, pstatus;
  22.     union
  23.     {                                   /* Access equiment either as:    */
  24.         unsigned u;                     /*   unsigned or                 */
  25.         struct                          /*   bit fields                  */
  26.         {
  27.             unsigned diskflag : 1;      /* Diskette drive installed?     */
  28.             unsigned coprocessor : 1;   /* Coprocessor? (except on PC)   */
  29.             unsigned sysram : 2;        /* Ram on system board           */
  30.             unsigned video : 2;         /* Startup video mode            */
  31.             unsigned disks : 2;         /* Drives 00=1, 01=2, 10=3, 11=4 */
  32.             unsigned dma : 1;           /* 0=Yes, 1=No (1 for PC Jr.)    */
  33.             unsigned comports : 3;      /* Serial ports                  */
  34.             unsigned game : 1;          /* Game adapter installed?       */
  35.             unsigned modem : 1;         /* Internal modem?               */
  36.             unsigned printers : 2;      /* Number of printers            */
  37.         } bits;
  38.     } equip;
  39.     static char y[] = "YES", n[] = "NO";
  40.  
  41.     /* Get current drive. */
  42.     _dos_getdrive( &drive );
  43.     printf( "Current drive:\t\t\t%c:\n", 'A' + drive - 1 );
  44.  
  45.     /* Set drive to current drive in order to get number of drives. */
  46.     _dos_setdrive( drive, &drivecount );
  47.  
  48.     _dos_getdiskfree( drive, &drvinfo );
  49.     printf( "Disk space free:\t\t%ld\n",
  50.             (long)drvinfo.avail_clusters *
  51.             drvinfo.sectors_per_cluster *
  52.             drvinfo.bytes_per_sector );
  53.  
  54.     /* Get new drive and number of logical drives in system. */
  55.     _dos_getdrive( &drive );
  56.     printf( "Number of logical drives:\t%d\n", drivecount );
  57.  
  58.     memory = _bios_memsize();
  59.     printf( "Memory:\t\t\t\t%dK\n", memory );
  60.  
  61.     equip.u = _bios_equiplist();
  62.  
  63.     printf( "Disk drive installed:\t\t%s\n", equip.bits.diskflag ? y : n );
  64.     printf( "Coprocessor installed:\t\t%s\n", equip.bits.coprocessor ? y : n );
  65.     printf( "Game adapter installed:\t\t%s\n", equip.bits.game ? y : n );
  66.     printf( "Serial ports:\t\t\t%d\n", equip.bits.comports );
  67.     printf( "Number of printers:\t\t%d\n", equip.bits.printers );
  68.  
  69.     /* Fail if any error bit is on, or if either operation bit is off. */
  70.     pstatus = _bios_printer( _PRINTER_STATUS, LPT1, 0 );
  71.     if( (pstatus & 0x29) || !(pstatus & 0x80) || !(pstatus & 0x10) )
  72.         pstatus = 0;
  73.     else
  74.         pstatus = 1;
  75.     printf( "Printer available:\t\t%s\n", pstatus ? y : n );
  76. }
  77.