Is it possible to convert a single file or a disk image/archive to Binary II format?
Closed this issue · 4 comments
I'm making a tool to identify and import Apple ][ binary executables and discovered the Binary II format which encapsulates the essential metadata from the filesystem/directory/catalog along with the file and a header.
But I can't find any .bny
files online and try as I might I can neither find a way to get CiderPress2 to convert a single file from a disk image or a whole disk image into Binary II format, nor can I find it stated that it's not a supported conversion target.
Am I missing something? Here are examples of my attempts:
% cp2 cfa APPLE.SYS.UTILS.DSK
File extension is not a file archive type
% cp2 cfa APPLE.SYS.UTILS.DSK bny
Usage: cp2 create-file-archive|cfa [options] <new-archive>
cfa: creates a new file archive
% cp2 export APPLE.SYS.UTILS.DSK bny
Error: unknown exporter 'bny'
% cp2 export APPLE.SYS.UTILS.DSK BNY
Error: invalid export spec 'BNY'
% cp2 export APPLE.SYS.UTILS.DSK BNY "*"
Error: invalid export spec 'BNY'
% cp2 export APPLE.SYS.UTILS.DSK .BNY "*"
Error: invalid export spec '.BNY'
% cp2 export APPLE.SYS.UTILS.DSK .bny "*"
Error: invalid export spec '.bny'
It's a two-step process that uses the "create-file-archive" and "copy" commands:
- create an empty BNY file
- copy files from the source archive into the BNY file
The "copy" command takes a list of file arguments. By default it copies all files found. For example:
% cp2 cfa new.bny
% cp2 copy PatchHFS.shk new.bny
Ignoring resource fork: 'patchhfs:PatchHFS.Doc'
copying patchhfs:PatchHFS.c
copying patchhfs:PatchHFS.Doc
copying patchhfs:Finder.Data
copying patchhfs:mkpatch
copying patchhfs:PatchHFS
By default, CiderPress II uses compression when adding to file archives, which for Binary II means "squeeze". You can disable this with the --no-compression
arg.
The Binary II format is older and doesn't support GS/OS resource forks. It's also worth noting that an empty BNY file is actually just an empty file, but it's good to follow the procedure above because it works for all other formats as well.
This works fine for ProDOS files. If you do this for files from a DOS disk you risk losing information. DOS 'T' files can be sparse, and DOS 'B'/'A'/'I' files have an embedded length that may differ from the full file length (see e.g. Hard Hat Mack). These aspects are preserved by "copy" for DOS-to-DOS transfers, but nothing other than a DOS filesystem is guaranteed to preserve the original structure. (The best archive format for DOS files is the DOS filesystem.)
Thanks! I'm actually just looking for a wrapper for DOS and ProDOS executable binaries that provides the missing load/entry address so I can make a Ghidra loader, so most of those limitations don't matter.
I plan to tackle a Ghidra FileSystem for .dsk/.do/.po later but they're trickier than most disk image formats thanks to the various orderings so that can wait (-:
You may just want to add a NAPS string onto the end. For example, a BIN file called "MYPROG" that loads at address $0800 would be "MYPROG#060800". One of my tests for NuLib2 was to extract the GS/OS System 6.0.1 boot disk files to Linux and add the files back, then boot the disk, to prove that all filenames, file types, aux types, and resource forks were preserved.
You can generate these with the "extract" command and "--preserve=naps":
% cp2 x -pn hard_hat_mack.dsk
extracting HELLO -> HELLO#fc0801
extracting HARD HAT MACK -> HARD HAT MACK#0607fd
When adding files, the strings are stripped and the attributes restored:
% cp2 a new.bny HELLO#fc0801 HARD\ HAT\ MACK#0607fd
Created file archive 'new.bny'
Adding 2 files
adding HARD HAT MACK#0607fd -> HARD HAT MACK
adding HELLO#fc0801 -> HELLO
% cp2 v new.bny
File: new.bny
Type Auxtyp Modified Format Length Size Name
---- ------ --------------- ------- -------- ---- ------------------------------
BIN $07FD 12-Aug-24 10:05 Stored 1019 100% HARD.HAT.MACK
BAS $0801 12-Aug-24 10:05 Stored 40 320% HELLO
The strings have been in use for 20+ years and are supported by many Apple II utilities. The syntax is summarized here, original documentation here.
The only down side is that there's no file extension added, so you have to look for the pattern (like this).
Oh thanks. I just pushed my BNY Loader but I'll add a NAPS Loader too.