home *** CD-ROM | disk | FTP | other *** search
/ YPA: Your Privacy Assured / YPA.ISO / other_goodies / utilities / amigaguid.lha / AmigaGuide / AG_V39 / Source / HyperBrowser / memory.c < prev    next >
C/C++ Source or Header  |  1993-01-08  |  2KB  |  82 lines

  1. /* memory.c
  2.  *
  3.  * (c) Copyright 1992 Commodore-Amiga, Inc.  All rights reserved.
  4.  *
  5.  * This software is provided as-is and is subject to change; no warranties
  6.  * are made.  All use is at your own risk.  No liability or responsibility
  7.  * is assumed.
  8.  *
  9.  */
  10.  
  11. #include "hyperbrowser.h"
  12.  
  13. /*****************************************************************************/
  14.  
  15. #define HEXASC  39
  16.  
  17. #define HEXSIZE 61
  18. #define OUTSIZE 512
  19.  
  20. void showmemory (struct GlobalData * gd, ULONG address)
  21. {
  22.     char *ptr = (char *) address;
  23.     char outbuf[OUTSIZE];
  24.     char *msg = NULL;
  25.     int counter = 0;
  26.     int cyc = 0;
  27.     ULONG *mem;
  28.     int i, max;
  29.     int c;
  30.  
  31.     /* Build the title */
  32.     strcpy (gd->gd_Node, "@{b}Memory@{ub}\n\n");
  33.  
  34.     if (address)
  35.     {
  36.     mem = ((ULONG *)address)-1;
  37.     max = MIN (*mem, 384);
  38.  
  39.     if (max == *mem)
  40.         bprintf (gd, "%08lx, %ld\n", address, *mem);
  41.     else
  42.         bprintf (gd, "%08lx\n", address);
  43.  
  44.     for (i = 0; i < max; i++)
  45.     {
  46.         c = (int *)(*ptr & 0xFF);
  47.         ptr++;
  48.  
  49.         if (!cyc)
  50.         {
  51.         /* Time to init the output buffer */
  52.         memset(outbuf, ' ', HEXSIZE);
  53.         outbuf[HEXSIZE-1] = 0;
  54.         }
  55.         counter++;
  56.  
  57.         msg = outbuf+(cyc<<1)+(cyc>>2);
  58.         msg[0] = "0123456789ABCDEF"[c>>4];
  59.         msg[1] = "0123456789ABCDEF"[c&15];
  60.         if (((c+1)&0x7f) <= ' ') c = '.';
  61.  
  62.         msg = "%04lx: %s\n";
  63.         outbuf[HEXASC+cyc] = c;
  64.         cyc++;
  65.         if (cyc != 16) continue;
  66.  
  67.         cyc = 0;
  68.         bprintf (gd, msg, counter, outbuf);
  69.         msg = NULL;
  70.     }
  71.  
  72.     if (msg)
  73.     {
  74.         bprintf (gd, msg, counter, outbuf);
  75.     }
  76.     }
  77.     else
  78.     {
  79.     strcat (gd->gd_Node, "NULL pointer\n");
  80.     }
  81. }
  82.