home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
mbug
/
mbug141.arc
/
CONVERT.LBR
/
CONVERT.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1979-12-31
|
4KB
|
153 lines
program convert_from_ed_to_asc_and_back;
const
cr=^M^J;
var
filename: file;
choice: char;
procedure ed_asc;
type
buffer = array[1..128] of byte;
var
ed, asc : file;
edbuf, ascbuf : buffer;
edpoint, ascpoint, linelen : byte;
temp1, i, linenum : integer;
temp2, edname, ascname :string[15];
function getnextch : integer;
begin
if edpoint=129 then
begin
blockread(ed,edbuf,1);
edpoint:=1;
end;
getnextch:=edbuf[edpoint];
edpoint:=edpoint+1
end;
procedure send(charout:byte);
begin
if ascpoint=129 then
begin
blockwrite(asc,ascbuf,1);
ascpoint:=1;
end;
ascbuf[ascpoint]:=charout;
ascpoint:=ascpoint+1;
end;
begin
ascpoint:=1;
edpoint:=129;
Writeln('Enter name of EDASM source file');
writeln('(without extension: must be type .edt)',cr);
write('==>>>');
readln(temp2); {collect file name}
ascname:=temp2+'.ASM'; {add approriate extension}
edname:=temp2+'.EDT';
assign(ed,edname);
assign(asc,ascname);
reset(ed); {open source file}
rewrite(asc); {open object file}
{both files now open & ready to go}
linenum:=getnextch+getnextch*256;
while linenum <> $FFFF do {test for EOF}
begin
linelen:=getnextch;
for i:=1 to linelen do {send the line of code}
send(getnextch);
send($0D); {send a cr/lf pair}
send($0A);
linenum:=getnextch+getnextch*256;
end;
send($1A); {send EOF marker}
blockwrite(asc,ascbuf,1);
writeln(cr,cr,'Translation complete.',cr,cr);
close(ed);
close(asc);
end;
procedure asc_ed;
type
buffer = array[1..128] of byte;
var
edbuf : buffer;
ascbuf : string[128];
edpoint, linelen, linenumhi : byte;
ed : file;
asc : text;
i, linenum: integer;
edname, ascname : string[15];
procedure send(charout:byte);
begin
if edpoint=129 then
begin
blockwrite(ed,edbuf,1);
edpoint:=1;
end;
edbuf[edpoint]:=charout;
edpoint:=edpoint+1;
end;
begin
edpoint:=1;
linenum:=100; {changing this alters the no. of the first line}
writeln('Enter name of ascii file for translation:');
writeln('without extension: must be type .asm',cr,cr);
write('==>>>');
readln(ascname);
edname:=ascname+'.edt';
ascname:=ascname+'.asm';
assign(ed,edname);
assign(asc,ascname);
rewrite(ed);
reset(asc);
while not eof(asc) and (linenumhi < 255) do
{end when eof(asc) is found or if .edt file becomes too long}
begin
readln(asc,ascbuf);
linelen:=length(ascbuf);
linenumhi:=linenum div 256;
send(linenum-linenumhi*256);
send(linenumhi);
linenum:=linenum+10; {calculate no. of next line; change to a
smaller increment if needed - i.e. when .edt file
becomes too long}
send(linelen);
for i:=1 to linelen do
send(ord(ascbuf[i]));
end;
send($FF);
send($FF);
blockwrite(ed,edbuf,1);
close(asc);
close(ed);
writeln(cr,cr,'Translation complete.',cr,cr);
end;
begin
writeln('Editor/assembler to Ascii conversion utility V1.0');
writeln(^I^I^I,'By Russell Butler',cr,cr);
writeln('1. Edasm to Ascii');
writeln('2. Ascii to Edasm',cr);
choice:=' ';
while (choice <> '1') and (choice <> '2') do
begin
write('Enter number of required option:');
readln(choice);
end;
if choice='1' then ed_asc
else asc_ed;
end.