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

  1. /*
  2. LD386.C -- undocumented DOS call from 386|DOS-Extender
  3.  
  4. Watcom C/386: wcl386 ld386
  5. 386|DOS-Extender: run386 ld386
  6. */
  7.  
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <dos.h>
  11.  
  12. #ifndef __WATCOMC__
  13. #error This program requires Watcom C/386
  14. #endif
  15.  
  16. typedef struct {
  17.     unsigned short intno, ds, es, fs, gs;
  18.     unsigned eax, edx;
  19.     } RMODE_PARAM_BLOCK;
  20.  
  21. main()
  22. {
  23.     RMODE_PARAM_BLOCK rpb;
  24.     union REGS r;
  25.     struct SREGS s;
  26.     char far *doslist;
  27.     unsigned lastdrv;
  28.     
  29.     /* load real-mode param block for INT 21h AH=52h */
  30.     memset(&rpb, 0, sizeof(RMODE_PARAM_BLOCK));  /* zero it out */
  31.     rpb.intno = 0x21;
  32.     rpb.eax = 0x5200;
  33.     
  34.     /* call 386|DOS-Extender service to "Issue Real Mode Interrupt,
  35.         Registers Specified" (INT 21h AX=2511h). */
  36.     r.x.eax = 0x2511;
  37.     r.x.edx = &rpb;
  38.     segread(&s);
  39.     int386x(0x21, &r, &r, &s);
  40.     
  41.     /* use 386|DOS-Extender selector 34h (writeable data segment that
  42.         maps the entire first megabyte of memory used by MS-DOS) */
  43.     doslist = MK_FP(0x34, (rpb.es << 4) + r.x.ebx);
  44.     
  45.     /* we now have protected-mode ptr to DOS List Of Lists -- 
  46.         use normally */
  47.     lastdrv = doslist[_osmajor==3 && _osminor==0 ? 0x1B : 0x21];
  48.     fputs("LASTDRIVE=", stdout);
  49.     putchar('A' - 1 + lastdrv);
  50.     putchar('\n');
  51.     return lastdrv;
  52. }
  53.