home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / OS_ID.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  4KB  |  171 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  OS_ID.C
  5. **
  6. **  Based upon public domain works by David Gibbs & Stephen Lindholm
  7. */
  8.  
  9. #define OS_ID_MAIN
  10. #include "snpdosys.h"
  11. #include <dos.h>
  12.  
  13. struct i_os_ver id_os_ver[TOT_OS];
  14. int id_os_type;
  15. int id_os;
  16.  
  17. const char *id_os_name[TOT_OS] = {
  18.       "DOS",
  19.       "OS/2 DOS",
  20.       "DESQview",
  21.       "Windows Std",
  22.       "Windows 386"
  23.       };
  24.  
  25. /*
  26. **  get_os() - Determine OS in use
  27. */
  28.  
  29. int get_os (void)
  30. {
  31.       union REGS t_regs;
  32.       int osmajor, osminor;
  33.       unsigned status;
  34.  
  35.       id_os_type = 0;
  36.       id_os = 0;
  37.  
  38.       /* test for DOS or OS/2 */
  39.  
  40.       t_regs.h.ah = 0x30;
  41.       int86(0x21, &t_regs, &t_regs);
  42.       osmajor = t_regs.h.al;
  43.       osminor = t_regs.h.ah;
  44.  
  45.       if (osmajor < 10)
  46.       {
  47.             id_os_ver[DOS].maj = osmajor;
  48.             id_os_ver[DOS].min = osminor;
  49.             id_os_type = id_os_type | is_DOS;
  50.       }
  51.       else
  52.       {
  53.             /* OS/2 v1.x DOS Box returns 0x0A */
  54.  
  55.             id_os_type = id_os_type | is_OS2;
  56.  
  57.             /* OS/2 v2.x DOS Box returns 0x14 */
  58.  
  59.             id_os_ver[OS2].maj = osmajor/10;
  60.             id_os_ver[OS2].min = osminor;
  61.       }
  62.  
  63.       /* test for Windows */
  64.  
  65.       t_regs.x.ax = 0x1600;         /* check enhanced mode operation    */
  66.       int86(0x2F, &t_regs, &t_regs);
  67.       status = t_regs.h.al;
  68.  
  69.       if ((0x00 == status) || (0x80 == status))
  70.       {
  71.             /*
  72.             ** Can't trust it...
  73.             **  let's check if 3.1 is running in standard mode or what?
  74.             */
  75.  
  76.             t_regs.x.ax = 0x160A;
  77.             int86( 0x2F, &t_regs, &t_regs );
  78.             if (0 == t_regs.x.ax)
  79.             {
  80.                   id_os_ver[WINS].maj = t_regs.h.bh;
  81.                   id_os_ver[WINS].min = t_regs.h.bl;
  82.                   id_os_type = id_os_type | is_WINS;
  83.             }
  84.       }
  85.       else if ((0x01 == status) || (0xff == status))
  86.       {
  87.             id_os_ver[WINS].maj = 2;
  88.             id_os_ver[WINS].min = 1;
  89.             id_os_type = id_os_type | is_WINS;
  90.       }
  91.       else
  92.       {
  93.             id_os_ver[WINS].maj = t_regs.h.al;
  94.             id_os_ver[WINS].min = t_regs.h.ah;
  95.             id_os_type = id_os_type | is_WINS;
  96.       }
  97.  
  98.       /* Test for DESQview */
  99.  
  100.       t_regs.x.cx = 0x4445;                /* load incorrect date */
  101.       t_regs.x.dx = 0x5351;
  102.       t_regs.x.ax = 0x2B01;                /*  DV set up call     */
  103.  
  104.       intdos(&t_regs, &t_regs);
  105.       if (t_regs.h.al != 0xFF)
  106.       {
  107.             id_os_type = id_os_type | is_DV;
  108.             id_os_ver[DV].maj = t_regs.h.bh;
  109.             id_os_ver[DV].min = t_regs.h.bl;
  110.       }
  111.  
  112.       if (id_os_type & is_DOS)
  113.             id_os = DOS;
  114.       if (id_os_type & is_WINS)
  115.             id_os = WINS;
  116.       if (id_os_type & is_WIN3)
  117.             id_os = WIN3;
  118.       if (id_os_type & is_DV)
  119.             id_os = DV;
  120.       if (id_os_type & is_OS2)
  121.             id_os = OS2;
  122.  
  123.       return(id_os);
  124. }
  125.  
  126. /*
  127. **  Give up a time slice to the OS
  128. */
  129.  
  130. void t_slice(int t_os)
  131. {
  132.       union REGS t_regs;
  133.     
  134.       switch (t_os)
  135.       {
  136.       case DOS  :
  137.             break;
  138.  
  139.       case OS2  :
  140.       case WIN3 :
  141.       case WINS :
  142.             t_regs.x.ax = 0x1680;
  143.             int86(0x2f,&t_regs,&t_regs);
  144.             break;
  145.  
  146.       case DV   :
  147.             t_regs.x.ax = 0x1000;
  148.             int86(0x15,&t_regs,&t_regs);
  149.             break;
  150.       } /* switch(t_os) */
  151. }
  152.  
  153.  
  154. #ifdef TEST
  155.  
  156. #include <stdio.h>
  157.  
  158. int main(void)
  159. {
  160.       int ostype = get_os();
  161.  
  162.       printf("%s version %d.%d\n",
  163.             id_os_name[ostype],
  164.             id_os_ver[ostype].maj,
  165.             id_os_ver[ostype].min);
  166.  
  167.       return(0);
  168. }
  169.  
  170. #endif /* TEST */
  171.