home *** CD-ROM | disk | FTP | other *** search
/ James Briskly's Game Magazine 2 / JBGM002S.ZIP / SOURCE / HOST_OS.CPP < prev    next >
C/C++ Source or Header  |  1995-08-22  |  2KB  |  115 lines

  1. // host_os.cpp    host operating system classes
  2. //        dave mccaldon (d.mccalden@staffordshire.ac.uk)
  3.  
  4. #include "host_os.h"
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <dos.h>
  9.  
  10. char *msdos_info (void)
  11. {
  12.     return ("MS-DOS version %d.%d");
  13. };
  14.  
  15. char *dosemu_info (void)
  16. {
  17.     return ("Linux dosemu version %d.%d");
  18. };
  19.  
  20. char *mswindows_info (void)
  21. {
  22.     return ("MS-Windows version %d.%d");
  23. };
  24.  
  25. char *desqview_info (void)
  26. {
  27.     return ("Desq-View version %d.%d");
  28. };
  29.  
  30. host_os::host_os (void)
  31. {
  32.     status = NOT_OK;
  33.     if (mswindows_detect () == true) format = mswindows_info;
  34. //    else if (dosemu_detect () == true) format = dosemu_info;
  35.     else if (desqview_detect () == true) format = desqview_info;
  36.     else
  37.     {
  38.         status = OK;
  39.         msdos_version ();
  40.         format = msdos_info;
  41.     }
  42. }
  43.  
  44.  
  45. char *host_os::information( char *p )
  46. {
  47.     if( p == NULL )
  48.         p = (char *) malloc( strlen( format() ) + 12 );
  49.     sprintf( p, format(), ver_major, ver_minor );
  50.  
  51.     return p;
  52. }
  53.  
  54. void host_os::msdos_version()
  55. {
  56.     ver_major = _osmajor;            // borlandc constants
  57.     ver_minor = _osminor;
  58. }
  59.  
  60. boolean host_os::mswindows_detect()
  61. {
  62.     union   REGS r;
  63.  
  64.     r.x.ax = 0x1600;
  65.     int86( 0x2F, &r, &r );
  66.     if( r.h.al & 0x7F )
  67.     {
  68.         ver_major = r.h.al;
  69.         ver_minor = r.h.ah;
  70.         return (true);
  71.     }
  72.  
  73.     return (false);
  74. }
  75.  
  76. boolean host_os::dosemu_detect()
  77. {
  78.     union   REGS r;
  79.  
  80.     // this is slightly more difficult than just calling the dosemu
  81.     // interrupt (0xE5), we need to check if the interrupt has a
  82.     // handler, as DOS and BIOS don't establish a default handler
  83.  
  84.     if( getvect( 0xE5 ) == NULL )
  85.         return (false);
  86.     r.x.ax = 0;
  87.     int86( 0xE5, &r, &r );
  88.     if( r.x.ax == 0xAA55 )            // check signature
  89.     {
  90.         ver_major = r.h.bh;
  91.         ver_minor = r.h.bl;
  92.         return (true);
  93.     }
  94.  
  95.     return (false);
  96. }
  97.  
  98. boolean host_os::desqview_detect()
  99. {
  100.     union   REGS r;
  101.  
  102.     r.x.ax = 0x2B01;                // AL=01 => get desqview version
  103.     r.x.cx = 0x4445;        // CX = 'DE'
  104.     r.x.dx = 0x5351;        // DX = 'SQ'
  105.     int86( 0x21, &r, &r );
  106.     if( r.h.al != 0xFF )
  107.     {
  108.         ver_major = r.h.bh;
  109.         ver_minor = r.h.bl;
  110.         return (true);
  111.     }
  112.  
  113.     return (false);
  114. }
  115.