RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
8bitexe.h
1#ifndef _8BITEXE_H
2#define _8BITEXE_H
3
4#include <algorithm>
5#include "binary.h"
6#include "../common.h"
7#include "../linker/module.h"
8#include "../linker/reader.h"
9#include "../linker/segment.h"
10#include "../linker/writer.h"
11
12/* TODO: this is all pretty much preliminary */
13/* TODO: combine into binary.h? */
14
15namespace Binary
16{
21 {
22 public:
23 /* TODO: untested */
24
25 /* TODO: enable setting the base address as a parameter */
26 /* TODO: SYS files are pure binary loaded at 0x2000 */
27
28 AppleFormat(uint64_t default_base_address = 0x0803, std::string default_extension = ".bin")
29 : GenericBinaryFormat(default_base_address, default_extension)
30 {
31 }
32
33 void ReadFile(Linker::Reader& rd) override;
34
35 void WriteFile(Linker::Writer& wr) override;
36 };
37
42 {
43 public:
44 /* TODO: untested */
45
46 /* TODO: enable setting the base address, default should be ??? */
47
48 /* exe, obj, com are also used */
49 AtariFormat(uint64_t default_base_address = 0, std::string default_extension = ".xex")
50 : GenericBinaryFormat(default_base_address, default_extension)
51 {
52 }
53
54 struct Segment
55 {
56 public:
57 uint16_t header;
58 bool header_optional;
59 uint16_t address;
60 std::shared_ptr<Linker::Writable> image;
61
62 Segment(bool header_optional = true)
63 : header(0xFFFF), header_optional(header_optional), address(0), image(nullptr)
64 {
65 }
66
67 Segment(uint16_t header)
68 : header(header), header_optional(false), address(0), image(nullptr)
69 {
70 }
71
72// ~Segment()
73// {
74// if(image)
75// delete image;
76// }
77
78 offset_t GetSize() const;
79
80 void ReadFile(Linker::Reader& rd);
81
82 void WriteFile(Linker::Writer& wr);
83 };
84
85 std::vector<std::unique_ptr<Segment>> segments;
86
88 static const uint16_t LOADER_ADDRESS = 0x02E2;
89
94 static const uint16_t ENTRY_ADDRESS = 0x02E0;
95
97 bool HasEntryPoint() const;
99 void AddEntryPoint(uint16_t entry);
100
101 void OnNewSegment(std::shared_ptr<Linker::Segment> segment) override;
102
103 void ProcessModule(Linker::Module& module) override;
104
105 void ReadFile(Linker::Reader& rd) override;
106
107 void WriteFile(Linker::Writer& wr) override;
108 };
109
114 {
115 public:
116 /* TODO */
117
119 static const uint16_t BASIC_START = 0x0801;
120
121 enum
122 {
123 BASIC_SYS = 0x9E, /* BASIC token */
124 };
125
126 std::shared_ptr<Linker::Segment> loader; /* loader routine in BASIC */
127
128 void Clear() override;
129
131 {
132 Clear();
133 }
134
135 void SetupDefaultLoader();
136
137 void ProcessModule(Linker::Module& module) override;
138
139 void WriteFile(Linker::Writer& wr) override;
140
141 std::string GetDefaultExtension(Linker::Module& module, std::string filename) override;
142 };
143
148 {
149 public:
150 /* TODO: untested */
151
152 uint8_t preinit_code[10] = { 0xC9 }; /* z80 return instruction */
153 bool loader_active = true;
154 uint8_t rsx_count = 0;
156 {
157 std::string name;
158 uint16_t offset;
159 uint16_t length; /* only used for reading */
160 bool nonbanked_only;
161 GenericBinaryFormat * module;
162 };
163 std::vector<rsx_record> rsx_table;
164
165 void Clear() override;
166
168 {
169 Clear();
170 }
171
172 void ReadFile(Linker::Reader& rd) override;
173
174 void WriteFile(Linker::Writer& wr) override;
175 };
176
181 {
182 public:
183 /* TODO: enable setting the base address, default should be ??? */
184
185 struct Segment
186 {
187 public:
188 uint16_t address;
189 uint16_t size; /* it is supposed to be at most 255, but we can store larger segments by cutting them into pieces */
190 std::shared_ptr<Linker::Writable> image;
191
192 void WriteFile(Linker::Writer& wr);
193 };
194
195 std::vector<std::unique_ptr<Segment>> segments;
196
197 void OnNewSegment(std::shared_ptr<Linker::Segment> segment) override;
198
199 void WriteFile(Linker::Writer& wr) override;
200
201 std::string GetDefaultExtension(Linker::Module& module, std::string filename) override;
202 };
203
208 {
209 public:
210 /* TODO: untested */
211
212 uint16_t zero_fill;
213
214 bool suppress_relocations;
215
216 std::set<uint16_t> relocations;
217
218 PRLFormat(uint64_t default_base_address = 0, std::string default_extension = ".prl")
219 : GenericBinaryFormat(default_base_address, default_extension)
220 {
221 }
222
223 void OnNewSegment(std::shared_ptr<Linker::Segment> segment) override;
224
225 bool ProcessRelocation(Linker::Module& module, Linker::Relocation& rel, Linker::Resolution resolution) override;
226
227 void WriteFile(Linker::Writer& wr) override;
228 };
229
234 {
235 public:
236 /* TODO */
237 bool uzi180_header;
238 uint16_t entry;
239
240 void ProcessModule(Linker::Module& module) override;
241
242 void WriteFile(Linker::Writer& wr) override;
243
245 std::string GetDefaultExtension(Linker::Module& module) override;
246 };
247
252 {
253 public:
254 std::shared_ptr<Linker::Writable> code, data;
255
256 void OnNewSegment(std::shared_ptr<Linker::Segment> segment) override;
257
258 /* TODO: apparently both .code and .data are loaded at 0x0100 */
259
260 void WriteFile(Linker::Writer& wr) override;
261
263 std::string GetDefaultExtension(Linker::Module& module) override;
264 };
265}
266
267#endif /* _8BITEXE_H */
BIN file for Apple ][.
Definition 8bitexe.h:21
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition 8bitexe.cc:20
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition 8bitexe.cc:8
EXE file for Atari 400/800.
Definition 8bitexe.h:42
static const uint16_t LOADER_ADDRESS
Address which contains a loader between to execute between loading segments.
Definition 8bitexe.h:88
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition 8bitexe.cc:118
void AddEntryPoint(uint16_t entry)
Attaches a new segment that contains the entry point.
Definition 8bitexe.cc:45
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition 8bitexe.cc:135
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition 8bitexe.cc:102
static const uint16_t ENTRY_ADDRESS
Address which contains the actual entry address after loading.
Definition 8bitexe.h:94
bool HasEntryPoint() const
An entry point is present if the memory address at EntryAddress has been filled by a segment.
Definition 8bitexe.cc:35
CP/M Plus .com file format.
Definition 8bitexe.h:148
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition 8bitexe.cc:204
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition 8bitexe.cc:238
void Clear() override
Resets all fields to their default values, deallocate memory.
Definition 8bitexe.cc:194
PRG file for Commodore PET/VIC-20/64.
Definition 8bitexe.h:114
std::string GetDefaultExtension(Linker::Module &module, std::string filename) override
Appends a default extension to the filename.
Definition 8bitexe.cc:187
void Clear() override
Resets all fields to their default values, deallocate memory.
Definition 8bitexe.cc:146
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition 8bitexe.cc:173
static const uint16_t BASIC_START
Address at which the BASIC program should start.
Definition 8bitexe.h:119
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition 8bitexe.cc:179
FLEX .cmd file format.
Definition 8bitexe.h:181
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition 8bitexe.cc:287
std::string GetDefaultExtension(Linker::Module &module, std::string filename) override
Appends a default extension to the filename.
Definition 8bitexe.cc:296
A template for flat binary formats.
Definition binary.h:21
std::string GetDefaultExtension(Linker::Module &module, std::string filename) override
Appends a default extension to the filename.
Definition binary.cc:183
MP/M .prl file format.
Definition 8bitexe.h:208
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 8bitexe.cc:306
bool ProcessRelocation(Linker::Module &module, Linker::Relocation &rel, Linker::Resolution resolution) override
Callback function to process relocations.
Definition 8bitexe.cc:316
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition 8bitexe.cc:329
UZI280 file format.
Definition 8bitexe.h:252
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 8bitexe.cc:388
std::string GetDefaultExtension(Linker::Module &module) override
Provides a default filename for the output file.
Definition 8bitexe.cc:419
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition 8bitexe.cc:406
UZI/UZI280 file formats.
Definition 8bitexe.h:234
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition 8bitexe.cc:369
std::string GetDefaultExtension(Linker::Module &module) override
Provides a default filename for the output file.
Definition 8bitexe.cc:381
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition 8bitexe.cc:363
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 representation of a value within some binary data that has to be fixed up once the exact position o...
Definition relocation.h:27
Representing a resolved relocation.
Definition resolution.h:17
A helper class, encapsulating functionality needed to export binary data.
Definition writer.h:15
Definition 8bitexe.h:55
Definition 8bitexe.h:156
Definition 8bitexe.h:186