home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / MBUG / MBUG071.ARC / MON.ART < prev    next >
Text File  |  1979-12-31  |  5KB  |  173 lines

  1.                Memory Display for Debugging in Turbo Pascal 
  2.                              Russell Crosser.
  3.  
  4.      ╔á havσ founΣ thσ followinτ procedurσ usefu∞ fo≥ debugginτ program≤ iε ì
  5. Turb∩á Pascal«á Thσá procedurσ display≤ ß numbe≥ oµ line≤ oµ memor∙á a⌠á 1╢ ì
  6. byte≤ pe≥ line¼á iε botΦ decima∞ anΣ ASCI╔ modes« Thσ wa∙ ╔ havσ useΣ i⌠ i≤ ì
  7. t∩á includσ ß cal∞ t∩ i⌠ a⌠ thσ poin⌠ iε memor∙ wherσ thσ probleφ seem≤á t∩ ì
  8. bσá occurring¼á givinτ thσ addres≤ oµ thσ suspec⌠ variablσ a≤ ßá parameter« ì
  9. Memor∙ froφ tha⌠ poin⌠ i≤ theε displayed¼ eithe≥ oε screeε o≥ oε ß printer¼ ì
  10. whicheve≥ i≤ convenient«á ╔ havσ madσ usσ oµ inversσ character≤ t∩á displa∙ ì
  11. thσá linσ oµ decima∞ numbers¼á a≤ therσ i≤ no⌠ rooφ fo≥ spaces«á Belo≈ i≤ ß ì
  12. selfstandinτ monito≥ prograφ usinτ thσ display.
  13.  
  14. The routine is called as follows:
  15.  
  16. PROCEDURE seemem(address,line,true);
  17.      The parameters are:
  18.           address: integer - first address to display
  19.           lines:   integer - no of lines of display
  20.           true if printer list wanted, or false for screen.
  21.                     ....ooooOoooo....
  22.  
  23. TYPE 
  24.   ascii =         SET OF 0..127;
  25.   allchar =       SET OF #0..#127;
  26.  
  27.   CONST 
  28.     crlf: SET OF byte = [13,10];
  29.     resp:  SET OF char = ['Y','y','N','n'];
  30.     respy: SET OF char = ['Y','y'];
  31.     anykey: ascii = [1..127];
  32.     print: ascii = [32..126];
  33.     nonspace: ascii = [33..126];
  34.  
  35.  
  36. PROCEDURE seemem(memad,lines: integer;list: boolean);
  37.  
  38. VAR 
  39.   memad2,i,j,k: integer;
  40.   memhex: STRING[4];
  41.   big: boolean;
  42.   yn: char;
  43.  
  44. FUNCTION toreal(i: integer): real;
  45. BEGIN {toreal}      {converts integer -32768 to +32767 
  46.                            to real    0 to 65535}
  47.   IF i < 0
  48.     THEN
  49.       toreal := 65536.0 + i
  50.     ELSE
  51.       toreal := i;
  52. END;
  53.  
  54. PROCEDURE printer;
  55. BEGIN
  56.   write(lst,'>>>>> Memory dump from ');
  57.   write(lst,toreal(memad): 6: 0,'  ( ',memhex,' hex)');
  58.   writeln(lst,'  16 bytes per line.');
  59.   FOR i := 0 TO lines DOè    BEGIN
  60.       IF i MOD 4 = 0
  61.         THEN
  62.           writeln(lst,toreal(memad+i*16): 5: 0,': ');
  63.       FOR j := 0 TO 15 DO
  64.         BEGIN
  65.           k := ord(mem[memad+i*16+j]);  {get memory value}
  66.           write(lst,k:3,' ');
  67.         END;
  68.       FOR j := 0 TO 15 DO
  69.         BEGIN
  70.           k := ord(mem[memad+i*16+j]);  {get memory value again}
  71.           IF NOT (k IN print)
  72.             THEN k := ord('.');         {dot if not printable}
  73.           write(lst,chr(k));            {print character}
  74.         END;
  75.     END;
  76.   writeln(lst);
  77.   writeln(lst);
  78.   writeln(lst);
  79. END;
  80.  
  81. PROCEDURE screen;
  82. BEGIN
  83.   clrscr;
  84.   write('>>>> Memory dump from ');
  85.   write(toreal(memad): 6: 0,'  ( ',memhex,' hex)');
  86.   writeln('  16 bytes per line');
  87.   FOR i := 0 TO lines DO
  88.     BEGIN
  89.       IF i MOD 4 = 0
  90.         THEN
  91.           writeln(toreal(memad+i*16)║ 5║ 0,'║ ')╗ 
  92.                     {writσ meφ location}
  93.       FOR j := 0 TO 7 DO
  94.         BEGIN
  95.           lowvideo;
  96.           k := ord(mem[memad+i*16+j*2]);     {get value}
  97.           write(k:3,' ');               {write inverse number}
  98.           normvideo;
  99.           k := ord(mem[memad+i*16+j*2+1]);
  100.           write(k:3);                   {next one normal}
  101.         END;
  102.       write('   ');
  103.       FOR j := 0 TO 15 DO
  104.         BEGIN
  105.           k := ord(mem[memad+i*16+j]);
  106.           IF NOT (k IN print)
  107.             THEN k := ord('.');         {dot if not printable}
  108.           write(chr(k));
  109.         END;
  110.       writeln;
  111.     END;
  112.   writeln(toreal(memad+(i+1)*16): 5: 0,': ');
  113. END;
  114.  
  115. PROCEDURE tohex;         {convert start no to hex}
  116. BEGIN
  117.   memhex := '    ';è  big := (memad < 0);
  118.   IF big
  119.     THEN memad2 := 32767 + memad +1
  120.     ELSE memad2 := memad;
  121.   FOR i := 4 DOWNTO 1 DO
  122.     BEGIN
  123.       j := memad2 MOD 16;
  124.       memad2 := memad2 DIV 16;
  125.       IF big AND (i = 1)
  126.         THEN j := 8+j;
  127.       memhex[i] := copy('0123456789ABCDEF',j+1,1);
  128.     END;
  129. END;
  130. BEGIN
  131.   tohex;
  132.   IF list
  133.     THEN printer
  134.     ELSE screen;
  135.   write('Press <SPACE> bar to continue......');
  136.   read(kbd,yn);
  137. END;
  138.  
  139.  
  140.                     ....ooooOoooo....
  141.  
  142. PROGRAM mon;
  143.  
  144. VAR 
  145.   place,place1: real;
  146.  
  147. {$I MONITOR.INC}
  148.  
  149. BEGIN
  150.   clrscr;
  151.   write('Input memory location (in decimal): ');
  152.   REPEAT
  153.     read(place)
  154.   UNTIL (place >=0) AND (place < 65536.0);
  155.   IF place = 32768.0
  156.     THEN place := 32767.0;
  157.   IF place > 32767.0
  158.     THEN place := place - 65536.0;
  159.   REPEAT
  160.     place1 := place;
  161.     seemem(trunc(place),15,false);
  162.     writeln;
  163.     REPEAT
  164.       write('Input another value (same value to stop): ');
  165.       read(place);
  166.     UNTIL (place >=0) AND (place < 65536.0);
  167.     IF place = 32768.0
  168.       THEN place := 32767.0;
  169.     IF place > 32767.0
  170.       THEN place := place - 65536.0;
  171.   UNTIL place1 = place;
  172. END.
  173.