home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / msc7.zip / HELLO.C < prev    next >
C/C++ Source or Header  |  1992-02-14  |  2KB  |  65 lines

  1. //
  2. // (c) Copyright 1992, Qualitas, Inc. All Rights Reserved
  3. //
  4. // Simple example of accessing DPMI library
  5. //
  6. #include <stdio.h>
  7. #include <dos.h>
  8. #include "dpmi.h"
  9.  
  10. void main(void)
  11. {    
  12.     int    dpmiStat;        // status return
  13.     uShort flags;            // 32-bitness flag
  14.     uChar  processor;        // processor type
  15.     uChar  majorVersion;        // major version number
  16.     uChar  minorVersion;        // minor version number
  17.     uShort nPrivateParas;        // size of host data
  18.     void (far* entryAddress)();    // switch entry point
  19.     struct freeMem_t freeMem;    // memory info structure
  20.  
  21. // The first call to the DPMI library is a query to detect the presence
  22. // of a DPMI host, and if found, to return information required to
  23. // make the initial entry into protected mode.
  24.  
  25.     dpmiStat=DPMIObtainSwitchEntryPoint(&flags, &processor, &majorVersion,
  26.             &minorVersion, &nPrivateParas, &entryAddress);
  27.     
  28.     if (dpmiStat != 0)
  29.     {
  30.         fprintf(stderr, "no DPMI host available\n");
  31.         exit(1);
  32.     }
  33.     else
  34.     {
  35.         printf("Host information:\n");
  36.         printf("\tFlags:\t\t%04x\n", flags);
  37.         printf("\tVersion:    %d.%d\n", majorVersion, minorVersion);
  38.         printf("\tProcessor:    80%d86\n", processor);
  39.         printf("\tPrivate data:\t%d paragraphs\n", nPrivateParas);
  40.         printf("\tEntry address:\t%04x:%04x\n", FP_SEG(entryAddress),
  41.             FP_OFF(entryAddress));
  42.     }
  43.     
  44. // If the DPMIObtainSwitchEntryPoint call succeeds, calling 
  45. // DPMIEnterProtectedMode switches the processor to protected mode.
  46.  
  47.     DPMIEnterProtectedMode(entryAddress, 16, nPrivateParas);
  48.     
  49. // Detect the current mode with DPMIGetCPUMode() -
  50.  
  51.     if (DPMIGetCPUMode() == 0)
  52.         printf("\nHello from Protected Mode!\n\n");
  53.  
  54.     else
  55.     {
  56.         fprintf(stderr, "entry to protected mode failed\n");
  57.         exit(1);
  58.     }
  59.  
  60. // Once in protected mode, you can use any of the DPMI library calls
  61.     
  62.     DPMIGetFreeMemory(&freeMem);
  63.     printf("Largest free memory block: 0x%08lx (%ld) bytes\n",
  64.         freeMem.largestFree, freeMem.largestFree);
  65. }