home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / emx / test / hw_mem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-19  |  1.5 KB  |  67 lines

  1. /* hw_mem.c (emx+gcc) */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <memory.h>
  6. #include <io.h>
  7. #include <sys/hw.h>
  8.  
  9. int main (int argc, char *argv[])
  10. {
  11.   unsigned char *p;
  12.   unsigned long address, length, base, end, i;
  13.   char *q;
  14.  
  15.   if (_osmode != DOS_MODE)
  16.     {
  17.       printf ("This programs runs under DOS, only.\n");
  18.       return (1);
  19.     }
  20.   if (argc != 3)
  21.     {
  22.       printf ("Usage: hw_mem <address> <length\n");
  23.       return (1);
  24.     }
  25.   errno = 0;
  26.   address = strtoul (argv[1], &q, 16);
  27.   if (errno != 0 || *q != 0)
  28.     {
  29.       printf ("hw_mem: invalid address\n");
  30.       return (1);
  31.     }
  32.   length = strtoul (argv[2], &q, 16);
  33.   if (errno != 0 || *q != 0 || length == 0)
  34.     {
  35.       printf ("hw_mem: invalid length\n");
  36.       return (1);
  37.     }
  38.   base = address & ~0xfff;
  39.   end = (address + length - 1) | 0xfff;
  40.   p = _memaccess (base, end, 0);
  41.   if (p == NULL)
  42.     {
  43.       perror ("hw_mem: _memaccess");
  44.       return (2);
  45.     }
  46.   p += address - base;
  47.   if (_isterm (fileno (stdout)))
  48.     setvbuf (stdout, NULL, _IOLBF, BUFSIZ);
  49.   printf ("%.8lx:", address & ~0x0f);
  50.   for (i = 0; i < (address & 0x0f); ++i)
  51.     printf ("   ");
  52.   for (i = 0; i < length; ++i)
  53.     {
  54.       printf (" %.2x", *p++);
  55.       ++address;
  56.       if ((address & 0xf) == 0)
  57.         {
  58.           putchar ('\n');
  59.           if (i + 1 < length)
  60.             printf ("%.8lx:", address);
  61.         }
  62.     }
  63.   if ((address & 0xf) != 0)
  64.     putchar ('\n');
  65.   return (0);
  66. }
  67.