![]() |
||||||||||||||||||||||||||
Home |
All ASCII based file formats have one disadvantage in common:
They all need more than double the amount of characters as opposed to the number of bytes to be sent.
Address fields and checksums will add even more characters.
So the shorter the records, the more characters have to be sent to get the file across.
The numbering system is in base 85 which may be somewhat hard to understand for us humans who are usually only familiar with base 10 numbers.
Some of us understand base 2 and base 16 as well, but base 85 is for most people something new.
Luckily we don't have to do any math with this number system.
We just convert a 32 bit binary number into a 5 digit number in base 85.
A 32 bit binary number has a range of 4,294,967,296, while a 5 digit number in base 85 has a range of 4,437,053,125, which is enough to do the trick.
One drawback is that we always have to send multiples of 4 bytes, even if we actually want to send 1, 2 or 3 bytes.
Unused bytes are padded with zeroes, which are discarded at the receiving end.
The benefit of this all is hopefully clear. For every 4 bytes we only have to send 5 ASCII characters, as opposed to 8 characters for all other formats.
Now we take a look at the the formatting of the FPC records. We look at the record at byte level, not at the actual base 85 encoded level. Only after formatting the FPC record at byte level we convert 4 bytes at a time to form a 5 digit base 85 number. If we don't have enough bytes in the record to fill the last group of 5 digits we will add bytes with the value of 0 behind the record. $ssccffffaaaaaaaadddddddd
Every record begins with the ASCII character "$". No spaces or tabs are allowed in a record. All other characters in the record are formed by groups of 5 digits of base 85.
This field is a one byte 2's-complement checksum of the entire record. To create the checksum make a 1 byte sum from all fields of the record: checksum = byte count + format flags + address bytes + all data bytes Then take the 2's-complement of this sum to create the final checksum. The 2's-complement is simply inverting all bits and then increment by 1. Checking the checksum at the receiver's end is done by adding all bytes together including the checksum itself, discarding all carries, and the result must be $00. The padding bytes at the end of the line, should they exist, should not be included in checksum. But it doesn't really matter if they are, for their influence will be 0 anyway.
The byte count cc counts the number of bytes in the current record minus 4.
So only the number of address bytes and the data bytes are counted and not the first 4 bytes of the record (checksum, byte count and format flags).
The byte count can have any value from $00 to $FF.
This is a 2 byte number, indicating what format is represented in this record.
Only a few formats are available, so we actually waste 1 byte in each record for the sake of having multiples of 4 bytes.
The first data byte of the record is stored in the address specified by the Address field aaaaaaaa.
After storing that data byte, the address is incremented by 1 to point to the address for the next data byte of the record.
And so on, until all data bytes are stored.
This field contains 0 or more data bytes. The actual number of data bytes is indicated by the byte count in the beginning of the record less the number of address bytes. The first data byte is stored in the location indicated by the address in the address field. After that the address is incremented by 1 and the next data byte is stored in that new location. This continues until all bytes are stored. If there are not enough data bytes to obtain a multiple of 4 we use $00 as padding bytes at the end of the record. These padding bytes are ignored on the receiving side.
End of file is recognized if the first four bytes of the record all contain $00. In base 85 this will be $%%%%% . This is the only decent way to terminate the file.
Now it's time for an example. In the first table you can see the byte representation of the file to be transferred. The 4th row of bytes is not a multiple of 4 bytes. But that does not matter, for we append $00 bytes at the end until we do have a multiple of 4 bytes. These padding bytes are not counted in the byte count however!
D81400000000B000576F77212044696420796F7520726561 Only after converting the bytes to base 85 we get the records of the FPC type file format presented in the next table. Note that there is always a multiple of 5 characters to represent a multiple of 4 bytes in each record.
$kL&@h%%,:,B.\?00EPuX0K3rO0JI)) The colour in the table above changes on each 5 digit group. As you can see the length of the lines is clearly shorter than the original ASCII lines. |