home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 8 / IOPROG_8.ISO / install / fips / source / host_os.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-25  |  2.2 KB  |  115 lines

  1. // host_os.cpp    host operating system classes
  2.  
  3. //        dave mccaldon (d.mccalden@staffordshire.ac.uk)
  4.  
  5.  
  6.  
  7. #include "host_os.h"
  8.  
  9. #include <stdio.h>
  10.  
  11. #include <stdlib.h>
  12.  
  13. #include <string.h>
  14.  
  15. #include <dos.h>
  16.  
  17.  
  18.  
  19. char *msdos_info (void)
  20.  
  21. {
  22.  
  23.     return ("MS-DOS version %d.%d");
  24.  
  25. };
  26.  
  27.  
  28.  
  29. char *dosemu_info (void)
  30.  
  31. {
  32.  
  33.     return ("Linux dosemu version %d.%d");
  34.  
  35. };
  36.  
  37.  
  38.  
  39. char *mswindows_info (void)
  40.  
  41. {
  42.  
  43.     return ("MS-Windows version %d.%d");
  44.  
  45. };
  46.  
  47.  
  48.  
  49. char *desqview_info (void)
  50.  
  51. {
  52.  
  53.     return ("Desq-View version %d.%d");
  54.  
  55. };
  56.  
  57.  
  58.  
  59. host_os::host_os (void)
  60.  
  61. {
  62.  
  63.     status = NOT_OK;
  64.  
  65.     if (mswindows_detect () == true) format = mswindows_info;
  66.  
  67. //    else if (dosemu_detect () == true) format = dosemu_info;
  68.  
  69.     else if (desqview_detect () == true) format = desqview_info;
  70.  
  71.     else
  72.  
  73.     {
  74.  
  75.         status = OK;
  76.  
  77.         msdos_version ();
  78.  
  79.         format = msdos_info;
  80.  
  81.     }
  82.  
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89. char *host_os::information( char *p )
  90.  
  91. {
  92.  
  93.     if( p == NULL )
  94.  
  95.         p = (char *) malloc( strlen( format() ) + 12 );
  96.  
  97.     sprintf( p, format(), ver_major, ver_minor );
  98.  
  99.  
  100.  
  101.     return p;
  102.  
  103. }
  104.  
  105.  
  106.  
  107. void host_os::msdos_version()
  108.  
  109. {
  110.  
  111.     ver_major = _osmajor;            // borlandc constants
  112.  
  113.     ver_minor = _osminor;
  114.  
  115. }
  116.  
  117.  
  118.  
  119. boolean host_os::mswindows_detect()
  120.  
  121. {
  122.  
  123.     union   REGS r;
  124.  
  125.  
  126.  
  127.     r.x.ax = 0x1600;
  128.  
  129.     int86( 0x2F, &r, &r );
  130.  
  131.     if( r.h.al & 0x7F )
  132.  
  133.     {
  134.  
  135.         ver_major = r.h.al;
  136.  
  137.         ver_minor = r.h.ah;
  138.  
  139.         return (true);
  140.  
  141.     }
  142.  
  143.  
  144.  
  145.     return (false);
  146.  
  147. }
  148.  
  149.  
  150.  
  151. boolean host_os::dosemu_detect()
  152.  
  153. {
  154.  
  155.     union   REGS r;
  156.  
  157.  
  158.  
  159.     // this is slightly more difficult than just calling the dosemu
  160.  
  161.     // interrupt (0xE5), we need to check if the interrupt has a
  162.  
  163.     // handler, as DOS and BIOS don't establish a default handler
  164.  
  165.  
  166.  
  167.     if( getvect( 0xE5 ) == NULL )
  168.  
  169.         return (false);
  170.  
  171.     r.x.ax = 0;
  172.  
  173.     int86( 0xE5, &r, &r );
  174.  
  175.     if( r.x.ax == 0xAA55 )            // check signature
  176.  
  177.     {
  178.  
  179.         ver_major = r.h.bh;
  180.  
  181.         ver_minor = r.h.bl;
  182.  
  183.         return (true);
  184.  
  185.     }
  186.  
  187.  
  188.  
  189.     return (false);
  190.  
  191. }
  192.  
  193.  
  194.  
  195. boolean host_os::desqview_detect()
  196.  
  197. {
  198.  
  199.     union   REGS r;
  200.  
  201.  
  202.  
  203.     r.x.ax = 0x2B01;                // AL=01 => get desqview version
  204.  
  205.     r.x.cx = 0x4445;        // CX = 'DE'
  206.  
  207.     r.x.dx = 0x5351;        // DX = 'SQ'
  208.  
  209.     int86( 0x21, &r, &r );
  210.  
  211.     if( r.h.al != 0xFF )
  212.  
  213.     {
  214.  
  215.         ver_major = r.h.bh;
  216.  
  217.         ver_minor = r.h.bl;
  218.  
  219.         return (true);
  220.  
  221.     }
  222.  
  223.  
  224.  
  225.     return (false);
  226.  
  227. }
  228.  
  229.