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 >
Wrap
Text File
|
1979-12-31
|
5KB
|
173 lines
Memory Display for Debugging in Turbo Pascal
Russell Crosser.
╔á havσ founΣ thσ followinτ procedurσ usefu∞ fo≥ debugginτ program≤ iε ì
Turb∩á Pascal«á Thσá procedurσ display≤ ß numbe≥ oµ line≤ oµ memor∙á a⌠á 1╢ ì
byte≤ pe≥ line¼á iε botΦ decima∞ anΣ ASCI╔ modes« Thσ wa∙ ╔ havσ useΣ i⌠ i≤ ì
t∩á includσ ß cal∞ t∩ i⌠ a⌠ thσ poin⌠ iε memor∙ wherσ thσ probleφ seem≤á t∩ ì
bσá occurring¼á givinτ thσ addres≤ oµ thσ suspec⌠ variablσ a≤ ßá parameter« ì
Memor∙ froφ tha⌠ poin⌠ i≤ theε displayed¼ eithe≥ oε screeε o≥ oε ß printer¼ ì
whicheve≥ i≤ convenient«á ╔ havσ madσ usσ oµ inversσ character≤ t∩á displa∙ ì
thσá linσ oµ decima∞ numbers¼á a≤ therσ i≤ no⌠ rooφ fo≥ spaces«á Belo≈ i≤ ß ì
selfstandinτ monito≥ prograφ usinτ thσ display.
The routine is called as follows:
PROCEDURE seemem(address,line,true);
The parameters are:
address: integer - first address to display
lines: integer - no of lines of display
true if printer list wanted, or false for screen.
....ooooOoooo....
TYPE
ascii = SET OF 0..127;
allchar = SET OF #0..#127;
CONST
crlf: SET OF byte = [13,10];
resp: SET OF char = ['Y','y','N','n'];
respy: SET OF char = ['Y','y'];
anykey: ascii = [1..127];
print: ascii = [32..126];
nonspace: ascii = [33..126];
PROCEDURE seemem(memad,lines: integer;list: boolean);
VAR
memad2,i,j,k: integer;
memhex: STRING[4];
big: boolean;
yn: char;
FUNCTION toreal(i: integer): real;
BEGIN {toreal} {converts integer -32768 to +32767
to real 0 to 65535}
IF i < 0
THEN
toreal := 65536.0 + i
ELSE
toreal := i;
END;
PROCEDURE printer;
BEGIN
write(lst,'>>>>> Memory dump from ');
write(lst,toreal(memad): 6: 0,' ( ',memhex,' hex)');
writeln(lst,' 16 bytes per line.');
FOR i := 0 TO lines DOè BEGIN
IF i MOD 4 = 0
THEN
writeln(lst,toreal(memad+i*16): 5: 0,': ');
FOR j := 0 TO 15 DO
BEGIN
k := ord(mem[memad+i*16+j]); {get memory value}
write(lst,k:3,' ');
END;
FOR j := 0 TO 15 DO
BEGIN
k := ord(mem[memad+i*16+j]); {get memory value again}
IF NOT (k IN print)
THEN k := ord('.'); {dot if not printable}
write(lst,chr(k)); {print character}
END;
END;
writeln(lst);
writeln(lst);
writeln(lst);
END;
PROCEDURE screen;
BEGIN
clrscr;
write('>>>> Memory dump from ');
write(toreal(memad): 6: 0,' ( ',memhex,' hex)');
writeln(' 16 bytes per line');
FOR i := 0 TO lines DO
BEGIN
IF i MOD 4 = 0
THEN
writeln(toreal(memad+i*16)║ 5║ 0,'║ ')╗
{writσ meφ location}
FOR j := 0 TO 7 DO
BEGIN
lowvideo;
k := ord(mem[memad+i*16+j*2]); {get value}
write(k:3,' '); {write inverse number}
normvideo;
k := ord(mem[memad+i*16+j*2+1]);
write(k:3); {next one normal}
END;
write(' ');
FOR j := 0 TO 15 DO
BEGIN
k := ord(mem[memad+i*16+j]);
IF NOT (k IN print)
THEN k := ord('.'); {dot if not printable}
write(chr(k));
END;
writeln;
END;
writeln(toreal(memad+(i+1)*16): 5: 0,': ');
END;
PROCEDURE tohex; {convert start no to hex}
BEGIN
memhex := ' ';è big := (memad < 0);
IF big
THEN memad2 := 32767 + memad +1
ELSE memad2 := memad;
FOR i := 4 DOWNTO 1 DO
BEGIN
j := memad2 MOD 16;
memad2 := memad2 DIV 16;
IF big AND (i = 1)
THEN j := 8+j;
memhex[i] := copy('0123456789ABCDEF',j+1,1);
END;
END;
BEGIN
tohex;
IF list
THEN printer
ELSE screen;
write('Press <SPACE> bar to continue......');
read(kbd,yn);
END;
....ooooOoooo....
PROGRAM mon;
VAR
place,place1: real;
{$I MONITOR.INC}
BEGIN
clrscr;
write('Input memory location (in decimal): ');
REPEAT
read(place)
UNTIL (place >=0) AND (place < 65536.0);
IF place = 32768.0
THEN place := 32767.0;
IF place > 32767.0
THEN place := place - 65536.0;
REPEAT
place1 := place;
seemem(trunc(place),15,false);
writeln;
REPEAT
write('Input another value (same value to stop): ');
read(place);
UNTIL (place >=0) AND (place < 65536.0);
IF place = 32768.0
THEN place := 32767.0;
IF place > 32767.0
THEN place := place - 65536.0;
UNTIL place1 = place;
END.