home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / SNIP9404.ZIP / OS_ID.C < prev    next >
C/C++ Source or Header  |  1994-04-03  |  3KB  |  135 lines

  1. /*
  2. **  OS_ID.C
  3. **
  4. **  based upon a public domain work by David Gibbs
  5. */
  6.  
  7. #define TEST
  8. #define OS_ID_MAIN
  9. #include "os_id.h"
  10. #include <dos.h>
  11.  
  12. struct i_os_ver id_os_ver[TOT_OS];
  13. int id_os_type;
  14. int id_os;
  15.  
  16. const char *id_os_name[TOT_OS] = {
  17.       "DOS",
  18.       "OS/2 DOS",
  19.       "DESQview",
  20.       "Windows Std",
  21.       "Windows 386"
  22.       };
  23.  
  24. int get_os (void)
  25. {
  26.       union REGS t_regs;
  27.       int osmajor, osminor;
  28.  
  29.       id_os_type = 0;
  30.       id_os = 0;
  31.  
  32.       /* test for DOS or OS/2 */
  33.  
  34.       t_regs.h.ah = 0x30;
  35.       int86(0x21, &t_regs, &t_regs);
  36.       osmajor = t_regs.h.al;
  37.       osminor = t_regs.h.ah;
  38.  
  39.       if (osmajor < 10)
  40.       {
  41.             id_os_ver[DOS].maj = osmajor;
  42.             id_os_ver[DOS].min = osminor;
  43.             id_os_type = id_os_type | is_DOS;
  44.       }
  45.       else
  46.       {
  47.             /* OS/2 v1.x DOS Box returns 0x0A */
  48.  
  49.             id_os_type = id_os_type | is_OS2;
  50.  
  51.             /* OS/2 v2.x DOS Box returns 0x14 */
  52.  
  53.             id_os_ver[OS2].maj = osmajor/10;
  54.             id_os_ver[OS2].min = osminor;
  55.       }
  56.  
  57.       /* test for Windows */
  58.  
  59.       t_regs.x.ax = 0x4680;
  60.       int86(0x2F, &t_regs, &t_regs);
  61.  
  62.       if (t_regs.x.ax == 0x0000)
  63.       {
  64.             id_os_ver[WINS].maj = 3;
  65.             id_os_ver[WINS].min = 0;
  66.             id_os_type = id_os_type | is_WINS;
  67.       }
  68.       else
  69.       {
  70.             t_regs.x.ax = 0x1600 ;
  71.             int86(0x2F, &t_regs, &t_regs);
  72.  
  73.             switch (t_regs.h.al)
  74.             {
  75.             case 0x00 :
  76.             case 0x80 :
  77.             case 0x01 :
  78.             case 0xFF :
  79.                   break;
  80.  
  81.             default   :
  82.                   id_os_type = id_os_type | is_WIN3;
  83.                   id_os_ver[WIN3].maj = t_regs.h.al;
  84.                   id_os_ver[WIN3].min = t_regs.h.ah;
  85.                   break ;
  86.             }  /* endswitch  */
  87.       } /* endif */
  88.  
  89.       /* Test for DESQview */
  90.  
  91.       t_regs.x.cx = 0x4445;                /* load incorrect date */
  92.       t_regs.x.dx = 0x5351;
  93.       t_regs.x.ax = 0x2B01;                /*  DV set up call     */
  94.  
  95.       intdos(&t_regs, &t_regs);
  96.       if (t_regs.h.al != 0xFF)
  97.       {
  98.             id_os_type = id_os_type | is_DV;
  99.             id_os_ver[DV].maj = t_regs.h.bh;
  100.             id_os_ver[DV].min = t_regs.h.bl;
  101.       }
  102.  
  103.       if (id_os_type & is_DOS)
  104.             id_os = DOS;
  105.       if (id_os_type & is_WINS)
  106.             id_os = WINS;
  107.       if (id_os_type & is_WIN3)
  108.             id_os = WIN3;
  109.       if (id_os_type & is_DV)
  110.             id_os = DV;
  111.       if (id_os_type & is_OS2)
  112.             id_os = OS2;
  113.  
  114.       return(id_os);
  115. }
  116.  
  117.  
  118. #ifdef TEST
  119.  
  120. #include <stdio.h>
  121.  
  122. int main(void)
  123. {
  124.       int ostype = get_os();
  125.  
  126.       printf("%s version %d.%d\n",
  127.             id_os_name[ostype],
  128.             id_os_ver[ostype].maj,
  129.             id_os_ver[ostype].min);
  130.  
  131.       return(0);
  132. }
  133.  
  134. #endif
  135.