Binaryii
Binaryii
developed by
Gary B. Little
Version History
---------------
November 24, 1986 : Initial release.
Background
----------
Transferring Apple II files in binary form to commercial information
services like CompuServe, Delphi, GEnie, and The Source is, to put it
mildly, a frustrating exercise. (For convenience, I'll refer to such
services, and any other non-Apple II systems, as "hosts.") Although
most hosts are able to receive a file's *data* in binary form (using
the Xmodem protocol, for example), they don't receive the file's all-
important attribute bytes. All the common Apple II operating systems,
notably ProDOS, store the attributes inside the disk directory, not
inside the file itself.
The ProDOS attributes are the access code, file type code, auxiliary
type code, storage type code, date of creation and last modification,
time of creation and last modification, the file size, and the name of
the file itself. (All these terms are defined in Apple's "ProDOS
Technical Reference Manual" or in the book "Apple ProDOS: Advanced
Features for Programmers" by Gary Little.) It is usually not possible
to use a ProDOS file's data without knowing what the file's attributes
are (particularly the file type code, auxiliary type code, and size).
This means ProDOS files uploaded in binary form to a host are useless
to those who download them. The same is true for DOS 3.3 and Pascal
files.
The "disk space needed" bytes contain the number of 512-byte disk
blocks the files inside the Binary II file will occupy after they've
been removed from the Binary II file. (The format of a Binary II file
containing multiple files is described below.) If the number is zero,
the person uploading the file did not bother to calculate the space
needed. The "disk space needed" must be placed in the file information
header for the first file inside the Binary II file; it can be set to
zero in subsequent headers. A downloading program can inspect "disk
space needed" and abort the transfer immediately if there isn't enough
disk free space.
The value of the "operating system type" byte indicates the native
operating system of the file:
Note that even if a file is not a ProDOS file, the attributes in the
file information header, including the name, must be inserted in
ProDOS form. Instructions on how to do this for DOS 3.3 files are
given later in this document. Similar considerations apply for the
files of other operating systems.
The "native file type code" has meaning only if the "operating system
type" is non-zero. It is set to the actual file type code assigned to
the file by its native operating system. (Some operating systems, such
as CP/M and MS-DOS, do not use file type codes, however.) Contrast
this with the file type code at +4, which is the closest equivalent
ProDOS file type code. The "native file type code" is needed to
distinguish files which have the same *ProDOS* file type, but which
may have different file types in their native operating system. Note
that if the file type code is only byte long (the usual case), the
high-order byte of "native file type code" is set to zero.
The ID bytes appear in the first two bytes of the phantom file.
Phantom files having a generic ID code of zero must contain lines of
text terminated by a $00 byte. The text must begin at the third byte
in the file.
The "data flags" byte is a bit vector indicating whether the data
portion of the Binary II file has been compressed, encrypted, or
packed. If bit 7 (the high-order bit) is set to 1, the file is
compressed. If bit 6 is 1, the file is encrypted. If bit 0 is 1, the
file is a sparse file that is packed. A Binary II downloading program
can examine this byte and warn the user, when necessary, that the file
must be expanded, decrypted, or unpacked. The person uploading a
Binary II file may use any convenient method for compressing,
encrypting, or packing the file but is responsible for providing
instructions on how to restore the file to its original state.
start end
-------------------------------------------------------------------
| Header #1 | #1 Data | Header #2 | #2 Data | Header #3 | #3 Data |
-------------------------------------------------------------------
+127 = 2 +127 = 1 +127 = 0
The "number of files to follow" byte (at offset 127) in the file
information header for each disk file contains the number of disk
files that follow it in the Binary II file. It will be zero in the
header for the last disk file in the group.
Filename Convention
-------------------
Whenever a file is sent to a host, the host asks the sender to provide
a name for it. If it's a Binary II file, the name provided should end
in .BNY so that its special form will be apparent to anyone viewing a
list of filenames.
(1) Set the name to one that adheres to the stricter ProDOS naming
rules.
(2) Set the ProDOS file type code, auxiliary type code, and access
code to values which correspond to the DOS 3.3 file type:
DOS 3.3 | ProDOS ProDOS ProDOS
file type | file type aux type access
-----------|----------- ---------- --------
$00 ( T) | $04 (TXT) $0000 $E3
$80 (*T) | $04 (TXT) $0000 $21
$01 ( I) | $FA (INT) $0C00 $E3
$81 (*I) | $FA (INT) $0C00 $21
$02 ( A) | $FC (BAS) $0801 $E3
$82 (*A) | $FC (BAS) $0801 $21
$04 ( B) | $06 (BIN) (*) $E3
$84 (*B) | $06 (BIN) (*) $21
$08 ( S) | $06 (BIN) $0000 $E3
$88 (*S) | $06 (BIN) $0000 $21
$10 ( R) | $FE (REL) $0000 $E3
$90 (*R) | $FE (REL) $0000 $21
$20 ( A) | $06 (BIN) $0000 $E3
$A0 (*A) | $06 (BIN) $0000 $21
$40 ( B) | $06 (BIN) $0000 $E3
$C0 (*B) | $06 (BIN) $0000 $21
(5) Set the end-of-file position to the length of the DOS 3.3
file, in bytes. For a B file (code $04 or $84), this number is
stored in the third and fourth bytes of the file. For an I
file (code $01 or $81) or an A file (code $02 or $82), this
number is stored in the first and second bytes of the file.
(7) Set the native file type code to the value of the DOS 3.3 file
type code.
Attribute bytes inside a DOS 3.3 file (if any) must *not* be included
in the data portion of the Binary II file. This includes the first
four bytes of a B (Binary) file, and the first two bytes of an A
(Applesoft) or I (Integer BASIC) file.
Acknowledgements
----------------
Thanks to Glen Bredon for suggesting that partial pathnames be allowed
in file information headers. Thanks also to Shawn Quick for suggesting
the "phantom file" byte, to Scott McMahan for suggesting the
compression and encryption bits in the "data flags" byte, and to
William Bond for suggesting the "disk space needed" bytes. Finally, a
big thank you to Neil Shapiro, Chief Sysop of MAUG, for supporting the
development of the Binary II format and helping it become a true
standard.
Feedback and Support
--------------------
Send any comments or questions concerning the Binary II file format
to:
Gary B. Little
#210 - 131 Water Street
Vancouver, British Columbia
Canada V6B 4M3
(604) 681-3371
CompuServe : 70135,1007
Delphi : GBL
MCI Mail : 658L6