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
/
MBUG159.ARC
/
MWB2ASC.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1979-12-31
|
6KB
|
154 lines
{Converts a Micro World BASIC program into a }
{text file. }
{Written in Turbo Pascal version 3.0 on Microbee}
{Written by Chris Topher Paul Gibson. }
{Commenced writing: 23/5/90 }
{Finished: 27/5/90 }
const
maxsect=64; {Buffer size}
{array of tokens used in microworld disk basic}
token: array[129..235] of string [9]
=('LET','LPRINT','PRINT','IF','NEW','LLIST',
'LIST','ELSE','THEN','FOR','NEXT','DIM','GOTO',
'OFF','ON','STOP','END','GOSUB','READ','DATA',
'RETURN','INPUT','RUN','RESTORE','TO','STEP',
'TAB','SPC','FN','VAR','POKE','OUT','REM',
'PRMT','ZONE','SD','CLEAR','EDIT','SET','RESET',
'SPEED','NORMAL','UNDERLINE','CSAVE','CLOAD',
'STRS','INVERSE','PCG','CURS','NOT','AND','OR',
'TRACE','CONT','CLS','HIRES','AUTO','INVERT',
'LORES','INT','IN','PEEK','USR','LEN','SEARCH',
'POINT','ERROR','POS','ASC','USED','NET','EOF',
'EDASM','GX','ABS','RND','FLT','FRE','VAL',
'FRACT','SGN','SQR','SIN','COS','ATAN','LOG',
'EXP','PLOT','DELETE','RENUM','PLAY','EXEC',
'STR','KEY','CHR','SAVE','LOAD','DIR','GRSAVE',
'GRLOAD','OPEN','CLOSE','NAME','KILL','AS',
'SYSTEM','DISKRESET');
type
NameType = string [20];
var
in_name , {holds name of input file}
out_name: NameType; {holds name of output file}
in_file : file; {Untyped input file.}
out_file: text; {Text output file.}
progdata: array[1..maxsect,0..127] of byte;
{big bit of MWB prog}
h,i,j,k : integer; {General counters.}
LnNo : real; {Line number.}
LnNoStr : string[6]; {line number as string.}
in_byte : byte; {One byte of program.}
end_in : boolean; {IndicatE end of input file}
error , {Error in file detected.}
CntOnErr: boolean; {Continue on error.}
InKey : char; {Can hold single key input.}
function NameFile(GivenName:NameType):NameType;
{NameFile searches file name given for extension}
{if no extension found appends .MWB to the name.}
begin {function NameFile}
if pos('.',GivenName) = 0 {see if there is a '.'}
then {if there wasn't}
NameFile:=GivenName+'.MWB' {add one.}
else {otherwise}
NameFile:=GivenName {don't}
end; {function NameFile}
function GetByte:byte; {single byte from in_file}
begin
if i>127 {have we drained that sector}
then {read sector if necessary}
begin
if h>k {have we emptied our buffer?}
then
begin
end_in:=eof(in_file); {Set that's all flag.}
k:=0;
while (k<>maxsect) and not eof(in_file) do
{while we have some file left and room}
{in buffer}
begin
k:=k+1; {set next buffer block}
blockread(in_file,progdata[k],1);
{get sector}
end;
h:=0;
end;
h:=h+1;
i:=0
end;
GetByte:=progdata[h,i]; {give value to this}
i:=i+1; {function}
end; {function GetByte}
begin {Main Program}
write('Convert Microworld basic into text. V1.0');
writeln;
write('Please enter name of .MWB file. ');
readln(in_name);
assign(in_file,NameFile(in_name)); {open file}
{$i-} reset(in_file) {$i+}; {see if file exists}
while ioresult<>0 do {while it doesn't}
begin {get another name}
writeln(NameFile(in_name),' not found');
write('Pleas re-enter name of file. ');
readln(in_name);
assign(in_file,NameFile(in_name));
{$i-} reset(in_file) {$i+}
end;
write('Please enter name of text output file. ');
readln(out_name);
assign(out_file,out_name);
rewrite(out_file); {open text file}
end_in:=false; {Not end of input file yet}
error:=false; {No error found yet}
CntOnErr:=false; {Don't continue on error yet}
h:=1;k:=0; {Sector no.}
i:=128; {Forces function GetByte to read sector}
{the first time it is called.}
in_byte:=GetByte; {Call it}
i:=64; {and ignore the first 64 bytes}
LnNo:=256.0*GetByte+GetByte; {Get 1st line number}
while not(end_in or (LnNo=65535.0)) {while not end}
and (CntOnErr or not error)
do {of input file or program}
begin
{write line number}
str(LnNo:1:0,LnNoStr); {convert to a string}
while length(LnNoStr)<5
do {Append leadig zeros}
LnNoStr:='0'+LnNoStr;
write(out_file,LnNoStr);
for j:=3 to GetByte do {one to end of line}
begin
in_byte:=GetByte; {Get a byte of program.}
if in_byte>128 {If byte is a token}
then {write it as such}
write(out_file,token[in_byte])
else {write text}
write(out_file,char(in_byte))
end; {for loop}
error:=error or (GetByte<>13); {Detect error}
if error and not CntOnErr
then {if error found and Continue not set.}
begin
write('Error detected in ');
write(NameFile(in_name),' Continue (Y/N) ');
read(kbd,InKey);
CntOnErr:=upcase(InKey)='Y';
end;
writeln(out_file); {new line}
LnNo:=GetByte*256.0+GetByte; {next line No.}
end; {while loop}
close(in_file);
close(out_file);
if error and not CntOnErr {If aborted error}
then
erase(out_file) {then remove the rubbish}
end. {program}