Added minimal AppleSingle support. (#11)

* Added minimal AppleSingle support.

This is just enough AppleSingle support to allow for putting files generated by cc65's default linker configuration into ProDOS images.

* Improved logging.

By the time the file is put into the ProDOS image, it isn't an AppleSingle file anymore.

* Minor comment update.
This commit is contained in:
Oliver Schmidt 2022-10-15 20:11:58 +02:00 committed by GitHub
parent 6b5045a788
commit a649647739
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 0 deletions

26
main.go
View File

@ -9,6 +9,7 @@
package main
import (
"encoding/binary"
"flag"
"fmt"
"os"
@ -116,6 +117,31 @@ func main() {
fmt.Printf("Failed to open input file %s: %s", inFileName, err)
os.Exit(1)
}
// Check for an AppleSingle file as produced by cc65
if // Magic number
binary.BigEndian.Uint32(inFile[0x00:]) == 0x00051600 &&
// Version number
binary.BigEndian.Uint32(inFile[0x04:]) == 0x00020000 &&
// Number of entries
binary.BigEndian.Uint16(inFile[0x18:]) == 0x0002 &&
// Data Fork ID
binary.BigEndian.Uint32(inFile[0x1A:]) == 0x00000001 &&
// Offset
binary.BigEndian.Uint32(inFile[0x1E:]) == 0x0000003A &&
// Length
binary.BigEndian.Uint32(inFile[0x22:]) == uint32(len(inFile)) - 0x3A &&
// ProDOS File Info ID
binary.BigEndian.Uint32(inFile[0x26:]) == 0x0000000B &&
// Offset
binary.BigEndian.Uint32(inFile[0x2A:]) == 0x00000032 &&
// Length
binary.BigEndian.Uint32(inFile[0x2E:]) == 0x00000008 {
fileType = int(binary.BigEndian.Uint16(inFile[0x34:]))
auxType = int(binary.BigEndian.Uint32(inFile[0x36:]))
inFile = inFile[0x3A:]
fmt.Printf("AppleSingle (File type: %02X, AuxType: %04X) detected\n", fileType, auxType)
}
err = prodos.WriteFile(file, pathName, fileType, auxType, inFile)
if err != nil {
fmt.Printf("Failed to write file %s: %s", pathName, err)