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
/
ENTERPRS
/
CPM
/
UTILS
/
A
/
CONVERTB.ARC
/
CONVERTB.DOC
< prev
next >
Wrap
Text File
|
1987-08-10
|
5KB
|
102 lines
CONVERTING TURBO PASCAL DATA FILES FROM CP/M TO MS\PC-DOS
by William Meacham 8/9/87
1004 Elm Street
Austin, Tx 78703
I found the editorial "A farewell to CP/M?" in TUG Lines,
the journal of the Turbo User Group, issue 19, very timely. I am
one of those who have made the transition from CP/M to DOS. One
of the nifty things about Turbo Pascal is that it was so easy!
My source code was almost completely transportable; I only had to
change a couple of BDOS calls. (The transition the other way
would not be so easy; you can do a lot of things on the IBM
clones that you can't on a CP/M machine.) However, I had a bit
more trouble transporting my data files. I could not just
transfer the files to the DOS machine and use them.
A CP/M Turbo Pascal data file (other than a text file)
differs from its DOS equivalent in two important ways: (1) it is
longer, and (2) it contains extra information. This means that
you cannot simply read the CP/M file from a DOS program; you have
to convert the file format.
The CP/M file is longer than its DOS equivalent because it
is rounded up to a 128-byte boundary. In CP/M the logical length
of a file is different from its physical length. By "logical
length" I mean the number of bytes in all the records in the file
as defined in your Turbo Pascal program. By "physical length" I
mean the file length recorded in the operating system directory.
CP/M does not keep track of the logical length of a file. Every
file is rounded up to the next 128-byte boundary (or 256 or 1K
byte, depending on your BIOS). DOS, however, keeps the exact
file length in its directory.
The CP/M file contains four bytes at its beginning not found
in the equivalent DOS file. These are two integers giving the
number of records and the record length. They are used for the
FileSize function, which works differently in CP/M from the way
it works in DOS. The CP/M FileSize function reads the first four
bytes of the file and computes its logical length. The DOS
function finds out from the directory. It does not need the
extra four bytes at the beginning, and the DOS data file does not
contain them.
This means you've got trouble when you transfer a CP/M file
to DOS, whether by modem or direct serial transfer or by using
a disk compatability program. If you recompile your source code
and then run it against the CP/M data file you either bomb out or
get erroneous results. Your Turbo program does not recognize the
extra four bytes at the beginning of the file, so all your
records are now four bytes off.
I wrote the program CONVERTB.PAS to fix this problem. It
will work on any CP/M data file that has been transferred to a
DOS machine. What it does is read the first four bytes and
compute the logical length of the file by multiplying the number
of records times the record length. Then it reads that many
bytes from the CP/M file and writes a new DOS file that many
bytes long. When you are done, the DOS file's logical and
physical length are the same.
The program is called "ConvertB" because it uses the Don
Taylor's buffered read routines in TUG Lines, Issue 18. The
input file is declared as an untyped file and read 32 128-byte
blocks at a time. This works because the file, having come from
CP/M, is a multiple of 128 bytes and we don't know or care, yet,
what its logical length is. We just want to read bytes.
The program uses a variant record, declared as type
"intbytes," to read the first four bytes. Looked at one way, an
intbyte variable is two bytes. Looked at another way it is an
integer. This is a powerful feature, not only of Turbo Pascal
but of standard Pascal as well; it allows us to access the same
information in two different ways. What we do is read two bytes
from the input file, then look at them as an integer representing
the number of records. Then we read two more bytes and look at
them as an integer representing the length of each record. We
must convert the integers to reals before multiplying them to get
the logical file length in bytes. If we did not and the result
were greater than 32,767 (maxint), the program would interpret it
as a negative file length.
Having computed the logical file length in bytes, all we do
is read that many bytes from the input file and write them to the
output file. An earlier version of this program just read a byte
at a time; using the buffered read routines speeds it up a lot.
However, we must write the output file one byte at a time. The
point is to write the exact number of bytes so that DOS will get
the file length right. If we used a buffered write routine, the
output file would be rounded up to a 128-byte boundary, which
would defeat the whole purpose.
This causes a lot of activity on your disk drives. I
recommend using a RAM disk if possible. If not, read from one
drive and write to another to minimize head movement. The
program is slow -- because it has to write the output one byte at
a time -- but you only have to run it once per data file.
I hope this helps others who are converting from CP/M to
DOS!