8#include "../linker/linker.h"
9#include "../linker/module.h"
10#include "../linker/segment.h"
11#include "../linker/writer.h"
17 typedef char OSType[4];
56 hfs_type home_file_system;
68 virtual offset_t GetLength();
73 virtual void CalculateValues();
77 static const char TXT_undefined[16];
78 static const char TXT_Macintosh[16];
79 static const char TXT_ProDOS[16];
80 static const char TXT_MS_DOS[16];
81 static const char TXT_UNIX[16];
82 static const char TXT_VAX_VMS[16];
85 std::vector<std::shared_ptr<Entry>> entries;
107 : type(type), version(version), home_file_system(version == 1 ? home_file_system : HFS_UNDEFINED)
109 assert(type == SINGLE || type == DOUBLE);
112 AppleSingleDouble(format_type type, hfs_type home_file_system)
113 : type(type), version(1), home_file_system(home_file_system)
115 assert(type == SINGLE || type == DOUBLE);
118 AppleSingleDouble(format_type type,
unsigned version = 2)
119 : type(type), version(version), home_file_system(HFS_UNDEFINED)
121 assert(type == SINGLE || type == DOUBLE);
125 explicit AppleSingleDouble(AppleSingleDouble& other, format_type type)
126 : type(type), version(other.version), home_file_system(other.home_file_system)
128 if(type == SINGLE && other.type == DOUBLE)
132 for(
auto entry : other.entries)
134 if(type == DOUBLE && entry->id == ID_DataFork)
136 entries.push_back(entry);
140 explicit AppleSingleDouble(AppleSingleDouble& other)
141 : type(other.type), version(other.version), home_file_system(other.home_file_system)
143 for(
auto entry : other.entries)
145 entries.push_back(entry);
149 void SetOptions(std::map<std::string, std::string>& options)
override;
150 void SetModel(std::string model)
override;
151 void SetLinkScript(std::string script_file, std::map<std::string, std::string>& options)
override;
153 std::shared_ptr<Entry> FindEntry(uint32_t
id);
156 std::shared_ptr<Entry> GetFileDatesInfo();
157 std::shared_ptr<Entry> GetMacintoshFileInfo();
158 std::shared_ptr<Entry> GetAUXFileInfo();
159 std::shared_ptr<Entry> GetProDOSFileInfo();
160 std::shared_ptr<Entry> GetMSDOSFileInfo();
162 std::shared_ptr<Entry> GetDataFork();
163 std::shared_ptr<Entry> GetResourceFork();
164 std::shared_ptr<Entry> GetFinderInfo();
167 void SetCreationDate(uint32_t CreationDate);
168 void SetModificationDate(uint32_t ModificationDate);
169 void SetBackupDate(uint32_t BackupDate);
170 void SetAccessDate(uint32_t AccessDate);
171 void SetMacintoshAttributes(uint32_t Attributes);
172 void SetProDOSAccess(uint16_t Access);
173 void SetProDOSFileType(uint16_t FileType);
174 void SetProDOSAUXType(uint32_t AUXType);
175 void SetMSDOSAttributes(uint16_t Attributes);
177 uint32_t GetCreationDate();
178 uint32_t GetModificationDate();
179 uint32_t GetMacintoshAttributes();
185 std::string PrefixFilename(std::string prefix, std::string filename);
186 std::string PrefixFilename(std::string prefix, std::string filename,
size_t limit);
187 std::string ReplaceExtension(std::string filename, std::string extension,
size_t limit);
189 std::string GetUNIXDoubleFilename(std::string filename);
190 std::string GetMacOSXDoubleFilename(std::string filename);
191 std::string GetProDOSDoubleFilename(std::string filename);
192 std::string GetMSDOSDoubleFilename(std::string filename);
203 : Entry(AppleSingleDouble::ID_DataFork)
225 using LinkerManager::SetLinkScript;
232 memory_model_t memory_model;
235 void SetOptions(std::map<std::string, std::string>& options)
override;
237 void SetModel(std::string model)
override;
246 Resource(
const char type[4], uint16_t
id, uint8_t attributes = 0)
247 : id(
id), attributes(attributes)
249 memcpy(this->type, type, 4);
252 Resource(
const char type[4], uint16_t
id, std::string name, uint8_t attributes = 0)
253 : id(
id), name(name), attributes(attributes)
255 memcpy(this->type, type, 4);
262 std::optional<std::string> name;
266 uint16_t name_offset = 0;
267 uint32_t data_offset = 0;
269 virtual offset_t GetLength() = 0;
280 std::shared_ptr<Linker::Segment> resource;
286 offset_t GetLength()
override;
305 uint32_t above_a5 = 0;
306 uint32_t below_a5 = 0;
307 std::vector<Entry> near_entries;
308 std::vector<Entry> far_entries;
314 offset_t GetLength()
override;
318 MOVE_DATA_SP = 0x3F3C,
328 std::shared_ptr<JumpTableCodeResource> jump_table;
329 std::shared_ptr<Linker::Segment> image;
331 CodeResource(uint16_t
id, std::shared_ptr<JumpTableCodeResource> jump_table)
332 :
Resource(
"CODE",
id), jump_table(jump_table)
337 uint32_t a5_address = 0;
338 uint32_t base_address = 0;
342 std::set<uint16_t> near_entries;
343 std::set<uint32_t> far_entries;
344 std::set<uint32_t> a5_relocations;
345 std::set<uint32_t> segment_relocations;
348 uint32_t first_near_entry_offset;
349 uint32_t first_far_entry_offset;
350 uint32_t a5_relocation_offset;
351 uint32_t segment_relocation_offset;
352 uint32_t resource_size;
358 offset_t GetLength()
override;
360 uint32_t MeasureRelocations(std::set<uint32_t>& relocations);
362 void WriteRelocations(
Linker::Writer& wr, std::set<uint32_t>& relocations);
376 uint16_t attributes = 0;
377 std::map<uint32_t, std::map<uint16_t, std::shared_ptr<Resource>>> resources;
380 uint32_t data_offset = 0, data_length = 0, map_offset = 0, map_length = 0;
381 uint16_t name_list_offset = 0;
382 std::map<uint32_t, uint16_t> reference_list_offsets;
385 std::shared_ptr<JumpTableCodeResource> jump_table;
386 std::vector<std::shared_ptr<CodeResource>> codes;
387 std::map<std::shared_ptr<Linker::Segment>, std::shared_ptr<CodeResource>> segments;
388 std::shared_ptr<Linker::Segment> a5world;
390 void AddResource(std::shared_ptr<Resource> resource);
392 void OnNewSegment(std::shared_ptr<Linker::Segment> segment)
override;
400 void CalculateValues()
override;
402 offset_t GetLength()
override;
417 : Entry(AppleSingleDouble::ID_RealName), name(name)
421 offset_t GetLength()
override;
430 : Entry(AppleSingleDouble::ID_Comment)
440 : Entry(AppleSingleDouble::ID_IconBW)
450 : Entry(AppleSingleDouble::ID_IconColor)
461 : Entry(AppleSingleDouble::ID_FileInfo)
475 uint32_t CreationDate;
476 uint32_t ModificationDate;
477 uint32_t LastBackupDate;
481 uint32_t ModificationDate = 0,
482 uint32_t LastBackupDate = 0,
483 uint32_t Attributes = 0)
484 : CreationDate(CreationDate), ModificationDate(ModificationDate), LastBackupDate(LastBackupDate), Attributes(Attributes)
488 offset_t GetLength()
override;
496 uint32_t CreationDate;
497 uint32_t ModificationDate;
502 ProDOS(uint32_t CreationDate = 0,
503 uint32_t ModificationDate = 0,
505 uint16_t FileType = 0,
506 uint32_t AUXType = 0)
507 : CreationDate(CreationDate), ModificationDate(ModificationDate), Access(Access), FileType(FileType), AUXType(AUXType)
511 offset_t GetLength()
override;
519 uint32_t ModificationDate;
522 MSDOS(uint32_t ModificationDate = 0,
523 uint16_t Attributes = 0)
524 : ModificationDate(ModificationDate), Attributes(Attributes)
528 offset_t GetLength()
override;
536 uint32_t CreationDate;
538 uint32_t ModificationDate;
540 AUX(uint32_t CreationDate = 0,
541 uint32_t AccessDate = 0,
542 uint32_t ModificationDate = 0)
543 : CreationDate(CreationDate), AccessDate(AccessDate), ModificationDate(ModificationDate)
547 offset_t GetLength()
override;
556 uint32_t CreationDate;
557 uint32_t ModificationDate;
562 uint32_t CreationDate = 0,
563 uint32_t ModificationDate = 0,
564 uint32_t BackupDate = 0,
565 uint32_t AccessDate = 0)
566 : Entry(AppleSingleDouble::ID_FileDatesInfo),
567 CreationDate(CreationDate), ModificationDate(ModificationDate), BackupDate(BackupDate), AccessDate(AccessDate)
571 offset_t GetLength()
override;
584 char Type[4] = {
'?',
'?',
'?',
'?' };
585 char Creator[4] = {
'?',
'?',
'?',
'?' };
587 Point Location = { 0, 0 };
590 : Entry(AppleSingleDouble::ID_FinderInfo)
594 offset_t GetLength()
override;
607 : Entry(AppleSingleDouble::ID_MacintoshFileInfo), Attributes(Attributes)
611 offset_t GetLength()
override;
625 uint16_t FileType = 0,
626 uint32_t AUXType = 0)
627 : Entry(AppleSingleDouble::ID_ProDOSFileInfo), Access(Access), FileType(FileType), AUXType(AUXType)
631 offset_t GetLength()
override;
643 : Entry(AppleSingleDouble::ID_MSDOSFileInfo), Attributes(Attributes)
647 offset_t GetLength()
override;
657 : Entry(AppleSingleDouble::ID_AFPShortName)
668 : Entry(AppleSingleDouble::ID_AFPFileInfo)
679 : Entry(AppleSingleDouble::ID_AFPDirectoryID)
699 version_t version, minimum_version;
701 uint16_t secondary_header_size = 0;
704 std::string generated_file_name;
707 :
AppleSingleDouble(AppleSingleDouble::DOUBLE), version(version), minimum_version(version <= MACBIN2 ? version : MACBIN2)
711 MacBinary(version_t version, version_t minimum_version)
712 :
AppleSingleDouble(AppleSingleDouble::DOUBLE), version(version), minimum_version(version < minimum_version ? version : minimum_version)
717 :
AppleSingleDouble(apple, AppleSingleDouble::DOUBLE), version(version), minimum_version(version < minimum_version ? version : minimum_version)
722 static uint16_t crc_step[256];
724 void CRC_Initialize();
726 void CRC_Step(uint8_t
byte = 0);
730 void WriteData(
Linker::Writer& wr,
size_t count,
const void * data);
732 void WriteData(
Linker::Writer& wr,
size_t count, std::string text);
758 TARGET_RESOURCE_FORK,
761 target_format_t target;
764 enum produce_format_t
766 PRODUCE_RESOURCE_FORK = 1 << 0,
767 PRODUCE_FINDER_INFO = 1 << 1,
768 PRODUCE_APPLE_DOUBLE = 1 << 2,
769 PRODUCE_MAC_BINARY = 1 << 3,
771 produce_format_t produce;
780 unsigned apple_single_double_version = 2;
782 AppleSingleDouble::hfs_type home_file_system = AppleSingleDouble::HFS_UNDEFINED;
784 MacBinary::version_t macbinary_version = MacBinary::MACBIN3, macbinary_minimum_version = MacBinary::MACBIN2;
786 MacDriver(target_format_t target = TARGET_DATA_FORK)
788 produce(target == TARGET_NONE ? PRODUCE_MAC_BINARY
789 : target == TARGET_DATA_FORK ? PRODUCE_APPLE_DOUBLE
790 : produce_format_t(0))
794 MacDriver(target_format_t target,
int produce)
795 : target(target), produce((produce_format_t)produce)
804 std::shared_ptr<AppleSingleDouble> container;
807 void SetOptions(std::map<std::string, std::string>& options)
override;
809 void SetModel(std::string model)
override;
811 void SetLinkScript(std::string script_file, std::map<std::string, std::string>& options)
override;
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition macos.cc:18
void WriteFile(Linker::Writer &out) override
Stores data in memory to file.
Definition macos.cc:28
AppleSingle & AppleDouble.
Definition macos.h:33
void SetOptions(std::map< std::string, std::string > &options) override
Passes command line parameters as settings over to format object.
Definition macos.cc:48
bool FormatSupportsResources() const override
Whether the format supports resources.
Definition macos.cc:13
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition macos.cc:8
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition macos.cc:526
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition macos.cc:660
std::string GetDefaultExtension(Linker::Module &module) override
Provides a default filename for the output file.
Definition macos.cc:696
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition macos.cc:560
void SetModel(std::string model) override
Sets the way memory is organized, typically modifying a built-in script.
Definition macos.cc:55
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition macos.cc:552
void SetLinkScript(std::string script_file, std::map< std::string, std::string > &options) override
Selects a script file to use for linking.
Definition macos.cc:60
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition macos.cc:1302
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition macos.cc:1289
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition macos.cc:1277
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition macos.cc:1248
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition macos.cc:1262
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition macos.cc:1316
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition macos.cc:1363
MacBinary is an alternative format to AppleSingle for representing a Macintosh file on a non-Macintos...
Definition macos.h:689
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition macos.cc:1549
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition macos.cc:1524
This is not actually a file format, but an interface to permit generating multiple binary outputs for...
Definition macos.h:751
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition macos.cc:1729
bool FormatSupportsResources() const override
Whether the format supports resources.
Definition macos.cc:1557
void SetLinkScript(std::string script_file, std::map< std::string, std::string > &options) override
Selects a script file to use for linking.
Definition macos.cc:1603
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition macos.cc:1734
bool AddSupplementaryOutputFormat(std::string subformat) override
If the output format actually drives multiple output formats (resource file, apple double,...
Definition macos.cc:1562
void SetModel(std::string model) override
Sets the way memory is organized, typically modifying a built-in script.
Definition macos.cc:1598
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition macos.cc:1608
void SetOptions(std::map< std::string, std::string > &options) override
Passes command line parameters as settings over to format object.
Definition macos.cc:1593
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition macos.cc:1339
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition macos.cc:1350
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition macos.cc:1237
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition macos.cc:811
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition macos.cc:815
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition macos.cc:887
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition macos.cc:737
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition macos.cc:733
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition macos.cc:746
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition macos.cc:751
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition macos.cc:755
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition macos.cc:779
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition macos.cc:728
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition macos.cc:723
A Macintosh resource fork.
Definition macos.h:218
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition macos.cc:1160
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition macos.cc:1217
void OnNewSegment(std::shared_ptr< Linker::Segment > segment) override
Callback function when allocating a new segment When the linker script runs, it creates segments cons...
Definition macos.cc:924
void SetModel(std::string model) override
Sets the way memory is organized, typically modifying a built-in script.
Definition macos.cc:706
void SetOptions(std::map< std::string, std::string > &options) override
Passes command line parameters as settings over to format object.
Definition macos.cc:701
bool FormatSupportsResources() const override
Whether the format supports resources.
Definition macos.h:220
std::string GetDefaultExtension(Linker::Module &module) override
Provides a default filename for the output file.
Definition macos.cc:1227
A helper class to collect sections into segments.
Definition linker.h:19
Encodes an object module file as a collection of sections, symbols and relocations.
Definition module.h:20
A helper class, encapsulating functionality needed to import binary data.
Definition reader.h:16
A helper class, encapsulating functionality needed to export binary data.
Definition writer.h:15