home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prof_c / util / memchk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  869 b   |  39 lines

  1. /*
  2.  *    memchk -- look for random-access memory at
  3.  *    a specified location; return non-zero if found
  4.  */
  5.  
  6. #include <dos.h>
  7. #include <memory.h>
  8.  
  9. int
  10. memchk(seg, os)
  11. unsigned int seg;
  12. unsigned int os;
  13. {
  14.     unsigned char tstval, oldval, newval;
  15.     unsigned int ds;
  16.     struct SREGS segregs;
  17.  
  18.     /* get value of current data segment */
  19.     segread(&segregs);
  20.     ds = segregs.ds;
  21.  
  22.     /* save current contents of test location */
  23.     movedata(seg, os, ds, (unsigned int)&oldval, 1);
  24.  
  25.     /* copy a known value into test location */
  26.     tstval = 0xFC;
  27.     movedata(ds, (unsigned int)&tstval, seg, os, 1);
  28.  
  29.     /* read test value back and comapre to value written */
  30.     movedata(seg, os, ds, (unsigned int)&newval, 1);
  31.     if (newval != tstval)
  32.         return (0);
  33.  
  34.     /* restore original contents of test location */
  35.     movedata(ds, (unsigned int)&oldval, seg, os, 1);
  36.  
  37.     return (1);
  38. }
  39.