home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l350 / 3.ddi / EXAMPLES / VDS / DMA.C
Encoding:
C/C++ Source or Header  |  1993-01-04  |  2.2 KB  |  79 lines

  1. /* 
  2. DMA.C -- uses Virtual DMA Services (VDS)
  3.  
  4. sample output:
  5. DMA Services 1.0
  6. Maximum DMA buffer: 196864 bytes
  7. Automatic remap not supported
  8. All memory not physically contiguous
  9. */ 
  10.  
  11. #include <stdlib.h> 
  12. #include <stdio.h> 
  13. #include <string.h>
  14. #include <dos.h> 
  15. #include <pharlap.h>
  16. #include <hw386.h>
  17.  
  18. #define CLEAR(x)        memset(&x, 0, sizeof(x)) 
  19.  
  20. typedef struct { 
  21.     unsigned long size; 
  22.     unsigned long linear_ofs; 
  23.     unsigned short seg; 
  24.     unsigned short buff_id; 
  25.     unsigned long phys_addr; 
  26.     } DDS;  /* DMA descriptor structure */ 
  27.  
  28. void fail(char *s) { puts(s); exit(1); } 
  29.  
  30. int lin_eq_phys(void)   // is linear==physical? 
  31.     REALPTR BiosRealp;
  32.     UCHAR BiosFlags;
  33.     RP_SET(BiosRealp, 0x7B, 0x40);  // Bios flags at 0040:007B
  34.     BiosFlags = PeekRealByte(BiosRealp);
  35.     return (!(BiosFlags & 0x20));   // check VDS present bit
  36.  
  37. int vds_get_version(unsigned *pmaj, unsigned *pmin,  
  38.                     unsigned *pmaxbuff, unsigned *pfeatures) 
  39.     SWI_REGS r; 
  40.     CLEAR(r); 
  41.     r.eax = 0x8102;
  42.     r.edx = 0; 
  43.     _dx_real_int(0x4b, &r);   // VDS uses INT 4Bh 
  44.     if (r.flags & EF_CF)
  45.         return 0;   // carry set -- VDS Get Version failed 
  46.     *pmaj = (r.eax >> 8) & 0xFF;
  47.     *pmin = r.eax & 0xFF;
  48.     *pmaxbuff = (r.esi << 16) + (r.edi & 0xFFFF); 
  49.     *pfeatures = r.edx & 0xFFFF; 
  50.     return 1; 
  51.      
  52. main() 
  53.     unsigned maj, min, maxbuff, features; 
  54.      
  55.     if (lin_eq_phys()) 
  56.         fail("linear == physical"); // no VDS 
  57.              
  58.     if (! vds_get_version(&maj, &min, &maxbuff, &features)) 
  59.         fail("VDS Get Version failed"); 
  60.     
  61.     // possibly check maj/min for reasonableness
  62.      
  63.     printf("DMA Services %d.%d\n", maj, min); 
  64.     printf("Maximum DMA buffer: %u bytes\n", maxbuff); 
  65.     if (features & 1) puts("PC/XT bus architecture (first meg only"); 
  66.     if (features & 2) puts("Physical buffer/remap region in first meg"); 
  67.     if (features & 4) puts("Automatic remap supported"); 
  68.     else              puts("Automatic remap not supported"); 
  69.     if (features & 8) puts("All memory physically contiguous"); 
  70.     else              puts("All memory not physically contiguous"); 
  71.      
  72.     return 0; 
  73.