From a649647739f04295e286499a5744c48066df0bfd Mon Sep 17 00:00:00 2001
From: Oliver Schmidt
Date: Sat, 15 Oct 2022 20:11:58 +0200
Subject: [PATCH] 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.
---
main.go | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/main.go b/main.go
index f68adfa..ef324ce 100644
--- a/main.go
+++ b/main.go
@@ -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)