home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l440 / 2.ddi / CHAP2 / OKAY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-25  |  2.4 KB  |  108 lines

  1. /*
  2. OKAY.C -- basic test for validity of undocumented DOS
  3.  
  4. cl -DTESTING -qc okay.c
  5. okay
  6. */
  7.  
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10.  
  11. #ifdef __TURBOC__
  12. #define ASM asm
  13. #pragma inline
  14. #elif defined(_MSC_VER) && (_MSC_VER >= 600)
  15. #define ASM _asm
  16. #else
  17. #error Requires inline assembler
  18. #endif      
  19.  
  20. typedef enum { FALSE, TRUE } BOOL;
  21.  
  22. BOOL netware(void);
  23. unsigned lastdrv_netware(void);
  24.  
  25. BOOL undoc_dos_okay(void)
  26. {
  27.     char far *doslist;
  28.     unsigned lastdrv_doc;
  29.     unsigned drive;
  30.  
  31.     /* get offset for LASTDRIVE within DOS List of Lists */
  32.     unsigned lastdrv_ofs = 0x21;
  33.     if (_osmajor==2) lastdrv_ofs = 0x10;
  34.     else if ((_osmajor==3) && (_osmajor==0)) lastdrv_ofs = 0x1b;
  35.  
  36.     /* Get DOS Lists of Lists */
  37.     ASM mov ah, 52h
  38.     ASM xor bx, bx
  39.     ASM mov es, bx
  40.     ASM int 21h
  41.     ASM mov doslist, bx
  42.     ASM mov doslist+2, es
  43.  
  44.     if (! doslist) 
  45.         return FALSE;
  46.  
  47.     /* use documented DOS to verify results */
  48. #ifdef __TURBOC__
  49.     lastdrv_doc = setdisk(getdisk());
  50. #else
  51.     _dos_getdrive(&drive);
  52.     _dos_setdrive(drive, &lastdrv_doc);
  53. #endif
  54.     if (doslist[lastdrv_ofs] == lastdrv_doc)
  55.         return TRUE;
  56.     else if (netware())
  57.     {
  58.         puts("Novell NetWare");
  59.         if (lastdrv_doc != 32)
  60.             puts("NetWare Function 0Eh looks strange");
  61.         return (doslist[lastdrv_ofs] == lastdrv_netware());
  62.     }
  63.  
  64.     return FALSE;
  65. }
  66.  
  67. /*
  68.     Novell Return Shell Version function (INT 21h AH=EAh AL=01h)
  69.     see "Interrupt List" on accompanying disk; also see Barry
  70.     Nance, Networking Programming in C, pp. 117, 341-2. Could also
  71.     test for presence of Novell IPX with INT 2Fh AX=7A00h.
  72. */
  73. BOOL netware(void)
  74. {
  75.     char buf[40];
  76.     char far *fp = buf;
  77.     ASM push di
  78.     ASM mov ax, 0EA01h
  79.     ASM mov bx, 0
  80.     ASM les di, fp
  81.     ASM int 21h
  82.     ASM xor al, al
  83.     ASM mov ax, bx
  84.     /* if BX still 0, then NetWare not present; return in AX */
  85.     ASM pop di
  86. }
  87.  
  88. /*
  89.     Novell Get Number of Local Drives function (INT 21h AH=DBh)
  90.     see "Interrupt List" on accompanying disk
  91. */
  92. unsigned lastdrv_netware(void)
  93. {
  94.     ASM mov ah, 0DBh
  95.     ASM int 21h
  96.     /* AL now holds number of "local drives" (i.e., LASTDRIVE) */
  97.     ASM xor ah, ah
  98.     /* unsigned returned in AX */
  99. }
  100.  
  101. #ifdef TESTING
  102. main()
  103. {
  104.     fputs("Undocumented DOS ", stdout);
  105.     puts( undoc_dos_okay() ? "ok" : "not ok");
  106. }
  107. #endif
  108.