Mercurial > hg > dmlib
annotate tools/objlink.c @ 2554:aabfa00eafd9
Improve error handling.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 27 Feb 2022 16:37:14 +0200 |
parents | 5c714feeb3a7 |
children | 6249aa494e83 |
rev | line source |
---|---|
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 * objlink - Link files (RAW and PRG) into one PRG object |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 * Programmed and designed by Matti 'ccr' Hamalainen |
2539 | 4 * (C) Copyright 2002-2021 Tecnic Software productions (TNSP) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 * |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 * Please read file 'COPYING' for information on license and distribution. |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 */ |
1432
a9516570cc26
Improve build, so that we can build the tools and tests with minimal
Matti Hamalainen <ccr@tnsp.org>
parents:
1431
diff
changeset
|
8 #include "dmtool.h" |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 #include "dmlib.h" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 #include "dmargs.h" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 #include "dmfile.h" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 |
2411 | 13 |
1681 | 14 #define SET_MAX_FILENAMES (128) |
15 #define SET_MAX_MEMBLOCKS (128) | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 /* Typedefs |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 */ |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 typedef struct |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 { |
864 | 22 int start, end; // Start and end address |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 int type; // Type |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 char *name; // Name of the block |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 int placement; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 } DMMemBlock; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 |
2411 | 28 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 typedef struct |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 char *name; // Description of memory model |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 char *desc; |
2553 | 33 int size; // Total addressable memory size |
34 int nmemBlocks; // Defined memory areas | |
1681 | 35 DMMemBlock memBlocks[SET_MAX_MEMBLOCKS]; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 } DMMemModel; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 |
2411 | 38 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 typedef struct |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 char *filename; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 int type; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 int placement; |
864 | 44 int addr; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 } DMSourceFile; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 |
2411 | 47 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 // Source file type |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 enum |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 STYPE_RAW = 1, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 STYPE_PRG, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 STYPE_PRGA |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 }; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 // How to determine block placement / address |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 enum |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 PLACE_STATIC = 1, // Already known |
2553 | 60 PLACE_ARGUMENT, // Commandline argument |
61 PLACE_FILE, // From file | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 }; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 enum |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 FMT_GENERIC = 1, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 FMT_PLAIN, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 FMT_DECIMAL |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
69 }; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 enum |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 MTYPE_NONE = 0, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 MTYPE_ROM, // Hard ROM |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 MTYPE_ROM_WT, // Write to RAM through ROM |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 MTYPE_IO, // I/O lines |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 MTYPE_RES // RESERVED |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 }; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 |
501
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
80 enum |
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
81 { |
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
82 LA_NONE = -2, |
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
83 LA_AUTO = -1 |
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
84 }; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 |
2411 | 86 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
87 /* Memory models |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
88 */ |
2411 | 89 const DMMemModel memoryModels[] = |
90 { | |
91 { "C64 unrestricted", "$01 = $34", | |
92 64 * 1024, | |
93 0, | |
94 { | |
95 { 0x0000, 0x0000, 0 , NULL , 0 } | |
96 } | |
97 }, | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 |
2411 | 99 { "C64 normal (IO+Basic+Kernal)", "$01 = $37", |
100 64 * 1024, | |
101 3, | |
102 { | |
103 { 0xA000, 0xBFFF, MTYPE_ROM_WT , "Basic ROM" , PLACE_STATIC }, | |
104 { 0xD000, 0xDFFF, MTYPE_IO , "I/O" , PLACE_STATIC }, | |
105 { 0xE000, 0xFFFF, MTYPE_ROM_WT , "Kernal ROM" , PLACE_STATIC }, | |
106 } | |
107 }, | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 |
2411 | 109 { "C64 modified (IO+Kernal)", "$01 = $36", |
110 64 * 1024, | |
111 2, | |
112 { | |
113 { 0xD000, 0xDFFF, MTYPE_IO , "I/O" , PLACE_STATIC }, | |
114 { 0xE000, 0xFFFF, MTYPE_ROM_WT , "Kernal ROM" , PLACE_STATIC }, | |
115 } | |
116 }, | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 |
2411 | 118 { "C64 modified (IO only)", "$01 = $35", |
119 64 * 1024, | |
120 1, | |
121 { | |
122 { 0xD000, 0xDFFF, MTYPE_IO , "I/O" , PLACE_STATIC }, | |
123 } | |
124 }, | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 |
2411 | 126 { "C64 modified (Char+Kernal+Basic)", "$01 = $33", |
127 64 * 1024, | |
128 3, | |
129 { | |
130 { 0xA000, 0xBFFF, MTYPE_ROM_WT , "Basic ROM" , PLACE_STATIC }, | |
131 { 0xD000, 0xDFFF, MTYPE_ROM , "Char ROM" , PLACE_STATIC }, | |
132 { 0xE000, 0xFFFF, MTYPE_ROM_WT , "Kernal ROM" , PLACE_STATIC }, | |
133 } | |
134 }, | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 }; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 static const int nmemoryModels = sizeof(memoryModels) / sizeof(memoryModels[0]); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 /* Global variables |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 */ |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 int nsrcFiles = 0; // Number of source files |
1681 | 143 DMSourceFile srcFiles[SET_MAX_FILENAMES]; // Source file names |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 int nmemBlocks = 0; |
1681 | 146 DMMemBlock memBlocks[SET_MAX_FILENAMES]; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 |
2411 | 148 char *optDestName = NULL; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 char *optLinkFileName = NULL; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 int optLinkFileFormat = FMT_GENERIC; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 BOOL optDescribe = FALSE, |
2411 | 152 optAllowOverlap = FALSE, |
153 optCropOutput = FALSE; | |
154 unsigned int optCropStart, optCropEnd; | |
155 unsigned int optInitValue = 0; | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 int optInitValueType = 1; |
2411 | 157 int optLoadAddress = LA_AUTO; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 int optMemModel = 0; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 const DMMemModel *memModel = NULL; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 Uint8 *memory = NULL; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 /* Arguments |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 */ |
860
daebbf28953d
The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
830
diff
changeset
|
165 static const DMOptArg optList[] = |
daebbf28953d
The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
830
diff
changeset
|
166 { |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
167 { 0, '?', "help" , "Show this help", OPT_NONE }, |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
168 { 1, 0, "license" , "Print out this program's license agreement", OPT_NONE }, |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
169 { 2, 'v', "verbose" , "Be more verbose", OPT_NONE }, |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
170 |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
171 { 10, 'r', "input-raw" , "RAW input: -r <file>:<addr>", OPT_ARGREQ }, |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
172 { 12, 'p', "input-prg" , "PRG input: -p <file>[:<addr>]", OPT_ARGREQ }, |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
173 { 14, 's', "section" , "Reserved section: -s <start>-<end>[,name] or <start>:<len>[,name]", OPT_ARGREQ }, |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
174 { 16, 'o', "output" , "Specify output file, -o <file>", OPT_ARGREQ }, |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
175 { 18, 'O', "overlap" , "Allow overlapping memory areas", OPT_NONE }, |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
176 { 20, 'm', "model" , "Set memory model", OPT_ARGREQ }, |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
177 { 22, 'l', "link-file" , "Output addresses and labels into file", OPT_ARGREQ }, |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
178 { 24, 'f', "format" , "Format of link-file: (g)eneric, (p)lain, (d)ecimal", OPT_ARGREQ }, |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
179 { 26, 'i', "init-value" , "Initialize memory with: -i <byte/word/dword>:[bwd]", OPT_ARGREQ }, |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
180 { 28, 'd', "describe" , "Output ASCII memory map description", OPT_NONE }, |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
181 { 30, 'c', "crop" , "Crop output file to: -c <start>-<end> or <start>:<len>", OPT_ARGREQ }, |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
182 { 32, 'L', "load-address" , "Set output file load address (or 'none' for 'raw' output)", OPT_ARGREQ }, |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 }; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 static const int optListN = sizeof(optList) / sizeof(optList[0]); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 void argShowHelp() |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 dmPrintBanner(stdout, dmProgName, "[options]"); |
2402
b7cd5dd0b82e
Merge one more change from th-libs args processing.
Matti Hamalainen <ccr@tnsp.org>
parents:
2384
diff
changeset
|
191 dmArgsPrintHelp(stdout, optList, optListN, 0, 80 - 2); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 |
2553 | 193 fprintf(stdout, |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 "\n" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 "Each numeric argument can be prefixed with $ or 0x for hexadecimal values.\n" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 "NOTICE! -p filename:<addr> will ignore load address and use <addr> instead!\n" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 "\n" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 "Available memory models:\n"); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 |
1678 | 200 for (int i = 0; i < nmemoryModels; i++) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
201 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
202 const DMMemModel *m = &memoryModels[i]; |
2553 | 203 fprintf(stdout, |
204 " %d = %-40s [%s] (%d kB)\n", | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 i, m->name, m->desc, m->size / 1024); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
207 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 off_t dmGetFileSize(FILE *f) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
212 off_t len, pos = ftell(f); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
213 fseeko(f, 0, SEEK_END); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 len = ftell(f); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 fseek(f, pos, SEEK_SET); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
216 return len; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
217 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
218 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
219 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
220 /* Memory block handling |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
221 */ |
2554 | 222 int dmReserveMemBlock(int startAddr, int endAddr, const char *blockName, int blockType) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 if (startAddr > endAddr) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
225 { |
2554 | 226 return dmError(DMERR_INVALID_ARGS, |
227 "ERROR! Block '%s' has startAddr=$%.4x > endAddr=$%.4x!\n", | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
228 blockName, startAddr, endAddr); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
229 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
230 |
1681 | 231 if (nmemBlocks < SET_MAX_FILENAMES) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
232 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 memBlocks[nmemBlocks].start = startAddr; |
497
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
234 memBlocks[nmemBlocks].end = endAddr; |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
235 memBlocks[nmemBlocks].name = dm_strdup(blockName); |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
236 memBlocks[nmemBlocks].type = blockType; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 nmemBlocks++; |
2554 | 238 return DMERR_OK; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
240 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
241 { |
2554 | 242 return dmError(DMERR_BOUNDS, |
243 "Maximum number of memBlock definitions (%d) exceeded!\n", | |
1681 | 244 SET_MAX_FILENAMES); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
245 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
246 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
247 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
248 |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
249 int dmCompareMemBlock(const void *cva, const void *cvb) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
250 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
251 const DMMemBlock *a = cva, *b = cvb; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
252 return a->start - b->start; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
253 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
254 |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
255 |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
864
diff
changeset
|
256 BOOL dmParseSection(const char *arg, unsigned int *sectStart, unsigned int *sectEnd, char **sectName, BOOL canHasName) |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
257 { |
497
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
258 char sectMode, *sep, *str, *namesep; |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
864
diff
changeset
|
259 unsigned int tmpi; |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
260 BOOL res = FALSE; |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
261 |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
262 // Define reserved section |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
263 // Create a copy of the argument |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
264 if ((str = dm_strdup(arg)) == NULL) |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
265 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
266 dmErrorMsg("Could not allocate temporary string!\n"); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
267 goto out; |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
268 } |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
269 |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
270 // Get start address |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
271 if ((sep = strchr(str, '-')) == NULL && |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
272 (sep = strchr(str, ':')) == NULL) |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
273 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
274 dmErrorMsg("Section definition '%s' invalid.\n", arg); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
275 goto out; |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
276 } |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
277 sectMode = *sep; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
278 *sep = 0; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
279 |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
280 // Get value |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1681
diff
changeset
|
281 if (!dmGetIntVal(str, sectStart, NULL)) |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
282 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
283 dmErrorMsg("Section start address '%s' in '%s' invalid.\n", str, arg); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
284 goto out; |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
285 } |
1238 | 286 |
497
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
287 // Check for name |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
288 namesep = strchr(sep + 1, ','); |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
289 if (canHasName && namesep != NULL) |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
290 { |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
291 *namesep = 0; |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
292 namesep++; |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
293 if (*namesep == 0) |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
294 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
295 dmErrorMsg("Section definition '%s' name is empty. Either specify name or leave it out.\n", |
497
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
296 arg); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
297 goto out; |
497
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
298 } |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
299 *sectName = dm_strdup(namesep); |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
300 } |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
301 else |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
302 if (namesep != NULL) |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
303 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
304 dmErrorMsg("Section definition does not allow a name, syntax error in '%s' at '%s'.\n", |
497
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
305 arg, namesep); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
306 goto out; |
497
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
307 } |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
308 |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
309 // Get end address or length |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1681
diff
changeset
|
310 if (!dmGetIntVal(sep + 1, &tmpi, NULL)) |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
311 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
312 dmErrorMsg("Section %s '%s' in '%s' invalid.\n", |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
313 sectMode == '-' ? "end address" : "length", |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
314 sep + 1, arg); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
315 goto out; |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
316 } |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
317 |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
318 if (sectMode == ':') |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
319 { |
497
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
320 *sectEnd = *sectStart + tmpi - 1; |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
321 } |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
322 else |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
323 { |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
324 if (tmpi < *sectStart) |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
325 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
326 dmErrorMsg("Section start address > end address in '%s'.\n", |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
327 arg); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
328 goto out; |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
329 } |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
330 *sectEnd = tmpi; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
331 } |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
332 |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
333 res = TRUE; |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
334 |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
335 out: |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
336 dmFree(str); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
337 return res; |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
338 } |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
339 |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
340 |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
341 BOOL dmParseInputFile(char *arg, const int type1, const int type2, const char *desc, BOOL requireAddr) |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
342 { |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
864
diff
changeset
|
343 unsigned int tmpi = 0; |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
344 BOOL hasAddr = FALSE; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
345 char *sep; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
346 |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
347 if ((sep = strrchr(arg, ':')) != NULL) |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
348 { |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
349 *sep = 0; |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1681
diff
changeset
|
350 if (!dmGetIntVal(sep + 1, &tmpi, NULL)) |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
351 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
352 dmErrorMsg("Invalid %s address '%s' specified for '%s'.\n", |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
353 desc, sep + 1, arg); |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
354 return FALSE; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
355 } |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
356 hasAddr = TRUE; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
357 } |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
358 else |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
359 if (requireAddr) |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
360 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
361 dmErrorMsg("No %s loading address specified for '%s'.\n", desc, arg); |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
362 return FALSE; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
363 } |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
364 |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
365 srcFiles[nsrcFiles].filename = arg; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
366 srcFiles[nsrcFiles].type = hasAddr ? type1 : type2; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
367 srcFiles[nsrcFiles].addr = tmpi; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
368 nsrcFiles++; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
369 return TRUE; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
370 } |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
371 |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
372 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
373 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
374 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
375 |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
376 switch (optN) |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
377 { |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
378 case 0: |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
379 argShowHelp(); |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
380 exit(0); |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
381 break; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
382 |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
383 case 1: |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
384 dmPrintLicense(stdout); |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
385 exit(0); |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
386 break; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
387 |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
388 case 2: |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
389 dmVerbosity++; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
390 break; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
391 |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
392 case 10: |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
393 // Add RAW |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
394 if (!dmParseInputFile(optArg, STYPE_RAW, STYPE_RAW, "RAW", TRUE)) |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
395 return FALSE; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
396 break; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
397 |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
398 case 12: |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
399 // Add PRG |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
400 if (!dmParseInputFile(optArg, STYPE_PRGA, STYPE_PRG, "PRG", FALSE)) |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
401 return FALSE; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
402 break; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
403 |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
404 case 14: |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
405 { |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
406 char *sectName = "Clear"; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
407 unsigned int sectStart, sectEnd, sectLen; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
408 if (!dmParseSection(optArg, §Start, §End, §Name, TRUE)) |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
409 return FALSE; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
410 |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
411 // Allocate memory block |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
412 sectLen = sectEnd - sectStart + 1; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
413 dmMsg(1, "Reserve $%.4x - $%.4x ($%x, %d bytes) as '%s'\n", |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
414 sectStart, sectEnd, sectLen, sectLen, sectName); |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
415 |
2554 | 416 if (dmReserveMemBlock(sectStart, sectEnd, sectName, MTYPE_RES) != DMERR_OK) |
1238 | 417 return FALSE; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
418 } |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
419 break; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
420 |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
421 case 16: |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
422 // Set output file name |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
423 optDestName = optArg; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
424 break; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
425 |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
426 case 18: |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
427 // Allow overlapping segments |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
428 optAllowOverlap = TRUE; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
429 break; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
430 |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
431 case 20: |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
432 // Set memory model |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
433 optMemModel = atoi(optArg); |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
434 if (optMemModel < 0 || optMemModel >= nmemoryModels) |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
435 { |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
436 dmErrorMsg("Invalid memory model number %i!\n", optMemModel); |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
437 return FALSE; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
438 } |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
439 break; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
440 |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
441 case 22: |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
442 // Linker file |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
443 optLinkFileName = optArg; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
444 break; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
445 |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
446 case 24: |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
447 // Linker file format |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
448 switch (tolower(optArg[0])) |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
449 { |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
450 case 'g': |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
451 optLinkFileFormat = FMT_GENERIC; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
452 break; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
453 case 'p': |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
454 optLinkFileFormat = FMT_PLAIN; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
455 break; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
456 case 'd': |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
457 optLinkFileFormat = FMT_DECIMAL; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
458 break; |
485
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
459 |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
460 default: |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
461 dmErrorMsg("Invalid/unknown linker file format '%s'!\n", |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
462 optArg); |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
463 return FALSE; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
464 } |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
465 break; |
485
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
466 |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
467 case 26: |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
468 // Initialization value |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
469 { |
2512 | 470 char *p; |
471 unsigned int tmpi; | |
472 | |
473 optInitValueType = 1; | |
474 if ((p = strrchr(optArg, ':')) != NULL) | |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
475 { |
2512 | 476 *p = 0; |
477 switch (tolower(p[1])) | |
478 { | |
479 case 'b': optInitValueType = 1; break; | |
480 case 'w': optInitValueType = 2; break; | |
481 case 'd': optInitValueType = 4; break; | |
482 default: | |
483 dmErrorMsg("Invalid init value type '%c' specified for '%s'.\n", | |
484 p[1], optArg); | |
485 return FALSE; | |
486 } | |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
487 } |
2512 | 488 if (!dmGetIntVal(optArg, &tmpi, NULL)) |
489 { | |
490 dmErrorMsg("Invalid initvalue '%s'.\n", optArg); | |
491 return FALSE; | |
492 } | |
493 optInitValue = tmpi; | |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
494 } |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
495 break; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
496 |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
497 case 28: |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
498 // Set describe mode |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
499 optDescribe = TRUE; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
500 break; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
501 |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
502 case 30: |
501
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
503 { |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
504 size_t cropLen; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
505 if (!dmParseSection(optArg, &optCropStart, &optCropEnd, NULL, FALSE)) |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
506 return FALSE; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
507 |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
508 cropLen = optCropEnd - optCropStart + 1; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
509 dmMsg(1, "Cutting output to $%.4x - $%.4x " |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
510 "($%" DM_PRIx_SIZE_T ", %" DM_PRIu_SIZE_T " bytes)\n", |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
511 optCropStart, optCropEnd, |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
512 cropLen, cropLen); |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
513 |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
514 optCropOutput = TRUE; |
501
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
515 } |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
516 break; |
501
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
517 |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
518 case 32: |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
519 // Set loading address |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
520 if (strcasecmp(optArg, "none") == 0) |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
521 { |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
522 optLoadAddress = LA_NONE; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
523 } |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
524 else |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
525 { |
2512 | 526 unsigned int tmpi; |
527 | |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
528 if (!dmGetIntVal(optArg, &tmpi, NULL)) |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
529 { |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
530 dmErrorMsg("Invalid loading address '%s'.\n", optArg); |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
531 return FALSE; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
532 } |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
533 if (tmpi >= 64*1024) |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
534 { |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
535 dmErrorMsg("Invalid or insane loading address %d/$%x!\n", |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
536 tmpi, tmpi); |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
537 return FALSE; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
538 } |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
539 optLoadAddress = tmpi; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
540 } |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
541 break; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
542 |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
543 default: |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
544 dmErrorMsg("Unimplemented option argument '%s'.\n", currArg); |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
545 return FALSE; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
546 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
547 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
548 return TRUE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
549 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
550 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
551 |
1676 | 552 int dmLoadPRG(const char *filename, const BOOL forceAddr, const int destAddr) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
553 { |
1674 | 554 FILE *fh; |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
555 int dataSize, loadAddr, endAddr, res = DMERR_OK; |
486 | 556 Uint16 tmpAddr; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
557 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
558 // Open the input file |
1674 | 559 if ((fh = fopen(filename, "rb")) == NULL) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
560 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
561 res = dmGetErrno(); |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
562 dmErrorMsg("Error opening input file '%s' #%d: %s.\n", |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
563 filename, res, dmErrorStr(res)); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
564 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
565 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
566 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
567 // Get filesize |
1674 | 568 if ((dataSize = dmGetFileSize(fh) - 2) < 0) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
569 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
570 res = dmGetErrno(); |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
571 dmErrorMsg("Error getting file size for '%s' #%d: %s.\n", |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
572 filename, res, dmErrorStr(res)); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
573 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
574 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
575 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
576 // Get loading address |
1674 | 577 if (!dm_fread_le16(fh, &tmpAddr)) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
578 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
579 res = dmGetErrno(); |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
580 dmErrorMsg("Error reading input file '%s' #%d: %s.\n", |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
581 filename, res, dmErrorStr(res)); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
582 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
583 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
584 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
585 // Show information |
486 | 586 loadAddr = forceAddr ? destAddr : tmpAddr; |
587 endAddr = loadAddr + dataSize - 1; | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
588 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
589 dmPrint(1, "* Loading '%s', %s at $%.4x-$%.4x", |
486 | 590 filename, forceAddr ? "PRGA" : "PRG", loadAddr, endAddr); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
591 |
486 | 592 if (endAddr >= memModel->size) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
593 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
594 res = DMERR_BOUNDS; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
595 dmPrint(1, " .. Does not fit into the memory!\n"); |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
596 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
597 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
598 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
599 // Load data |
1674 | 600 if (fread(&memory[loadAddr], dataSize, 1, fh) < 1) |
486 | 601 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
602 res = dmGetErrno(); |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
603 dmPrint(1, " .. Error #%d: %s.\n", |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
604 res, dmErrorStr(res)); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
605 goto out; |
486 | 606 } |
607 | |
608 dmPrint(1, " .. OK\n"); | |
609 | |
610 // Add to list of blocks | |
2554 | 611 if ((res = dmReserveMemBlock(loadAddr, endAddr, filename, MTYPE_RES)) != DMERR_OK) |
612 goto out; | |
486 | 613 |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
614 out: |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
615 if (fh != NULL) |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
616 fclose(fh); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
617 |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
618 return res; |
486 | 619 } |
620 | |
621 | |
864 | 622 int dmLoadRAW(const char *filename, const int destAddr) |
486 | 623 { |
1674 | 624 FILE *fh; |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
625 int dataSize, endAddr, res = DMERR_OK; |
486 | 626 |
627 // Open the input file | |
1674 | 628 if ((fh = fopen(filename, "rb")) == NULL) |
486 | 629 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
630 res = dmGetErrno(); |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
631 dmErrorMsg("Error opening input file '%s' #%d: %s.\n", |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
632 filename, res, dmErrorStr(res)); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
633 goto out; |
486 | 634 } |
635 | |
636 // Get filesize | |
1674 | 637 if ((dataSize = dmGetFileSize(fh)) < 0) |
486 | 638 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
639 res = dmError(DMERR_FREAD, |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
640 "Error getting file size for '%s'.\n", filename); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
641 goto out; |
486 | 642 } |
643 | |
644 // Show information | |
645 endAddr = destAddr + dataSize - 1; | |
646 dmPrint(1, "* Loading '%s', RAW at $%.4x-$%.4x", | |
647 filename, destAddr, endAddr); | |
648 | |
649 if (endAddr >= memModel->size) | |
650 { | |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
651 res = DMERR_BOUNDS; |
486 | 652 dmPrint(1, " .. Does not fit into the memory!\n"); |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
653 goto out; |
486 | 654 } |
655 | |
656 // Load data | |
1674 | 657 if (fread(&memory[destAddr], dataSize, 1, fh) < 1) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
658 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
659 res = dmGetErrno(); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
660 dmPrint(1, " .. Error reading data #%d: %s.\n", |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
661 res, dmErrorStr(res)); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
662 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
663 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
664 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
665 dmPrint(1, " .. OK\n"); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
666 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
667 // Add info to list |
2554 | 668 if ((res = dmReserveMemBlock(destAddr, endAddr, filename, MTYPE_RES)) != DMERR_OK) |
669 goto out; | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
670 |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
671 out: |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
672 if (fh != NULL) |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
673 fclose(fh); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
674 |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
675 return res; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
676 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
677 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
678 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
679 int outputLinkData(FILE *dfile, const char *blockName, const int blockStart, const int blockEnd) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
680 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
681 char *tmpStr, *s, *t; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
682 int blockSize; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
683 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
684 blockSize = (blockEnd - blockStart + 1); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
685 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
686 // Create label name from filename |
2554 | 687 if ((tmpStr = dm_strdup(blockName)) == NULL) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
688 { |
2554 | 689 return dmError(DMERR_MALLOC, |
690 "Could not allocate memory for string '%s'!\n", | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
691 blockName); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
692 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
693 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
694 if ((t = strrchr(tmpStr, '/'))) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
695 s = (t + 1); |
1678 | 696 else |
697 if ((t = strrchr(tmpStr, '\\'))) | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
698 s = (t + 1); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
699 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
700 s = tmpStr; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
701 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
702 if ((t = strrchr(s, '.'))) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
703 *t = 0; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
704 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
705 for (t = s; *t; t++) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
706 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
707 if (!isalnum(*t)) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
708 *t = '_'; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
709 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
710 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
711 // Print the label line |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
712 switch (optLinkFileFormat) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
713 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
714 case FMT_PLAIN: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
715 fprintf(dfile, "%s = $%.4x\n", tmpStr, blockStart); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
716 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
717 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
718 case FMT_DECIMAL: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
719 fprintf(dfile, "%s = %d\n", tmpStr, blockStart); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
720 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
721 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
722 case FMT_GENERIC: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
723 default: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
724 fprintf(dfile, "; %s ($%.4x - $%.4x, %d/$%x bytes)\n", |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
725 blockName, blockStart, blockEnd, blockSize, blockSize); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
726 fprintf(dfile, "%s = $%.4x\n", s, blockStart); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
727 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
728 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
729 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
730 dmFree(tmpStr); |
2554 | 731 return DMERR_OK; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
732 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
733 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
734 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
735 /* Print out an ASCII presentation of memory map |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
736 */ |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
737 void memPrintLine(FILE *f) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
738 { |
2553 | 739 fprintf(f, |
740 " +------------------------------------------+\n"); | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
741 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
742 |
864 | 743 void memPrintEmpty(FILE *f, int n) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
744 { |
1678 | 745 for (int i = 0; i < n; i++) |
2553 | 746 fprintf(f, |
747 " | |\n"); | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
748 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
749 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
750 void dmDescribeMemory(FILE *f) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
751 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
752 DMMemBlock *prev = NULL; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
753 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
754 memPrintLine(f); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
755 |
1678 | 756 for (int i = 0; i < nmemBlocks; i++) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
757 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
758 DMMemBlock *curr = &memBlocks[i]; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
759 char desc[512], *s; |
864 | 760 int siz, kz; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
761 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
762 // Check for empty, unreserved areas |
828 | 763 if (prev != NULL) |
764 siz = (curr->start - 1) - (prev->end + 1) + 1; | |
765 else | |
766 siz = 0; | |
1238 | 767 |
499
c9b83226e21a
Fix empty blocks size calculation, was off by one.
Matti Hamalainen <ccr@tnsp.org>
parents:
498
diff
changeset
|
768 if (prev != NULL && siz > 1) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
769 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
770 kz = siz / (1024 * 2); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
771 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
772 if (kz > 1) memPrintEmpty(f, kz); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
773 |
500
49701129c5dd
Remove the redundant word 'bytes' from Empty sections in describe output.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
774 snprintf(desc, sizeof(desc), "EMPTY (%d)", siz); |
498
270a2d695607
Describe option did not actually show the unreserved/unused areas of the
Matti Hamalainen <ccr@tnsp.org>
parents:
497
diff
changeset
|
775 fprintf(f, "$%.4x - $%.4x | %-40s |\n", prev->end + 1, curr->start - 1, desc); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
776 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
777 if (kz > 1) memPrintEmpty(f, kz); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
778 memPrintLine(f); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
779 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
780 prev = curr; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
781 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
782 // Print current block |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
783 switch (curr->type) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
784 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
785 case MTYPE_NONE: s = "N/A (NC)"; break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
786 case MTYPE_ROM: s = "ROM"; break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
787 case MTYPE_ROM_WT: s = "ROM/WT"; break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
788 case MTYPE_IO: s = "I/O"; break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
789 case MTYPE_RES: s = "RSVD"; break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
790 default: s = "????"; break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
791 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
792 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
793 siz = curr->end - curr->start + 1; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
794 kz = siz / (1024 * 2); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
795 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
796 if (kz > 1) memPrintEmpty(f, kz); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
797 snprintf(desc, sizeof(desc), "%s (%s, %d)", curr->name, s, siz); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
798 fprintf(f, "$%.4x - $%.4x | %-40s |\n", curr->start, curr->end, desc); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
799 if (kz > 1) memPrintEmpty(f, kz); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
800 memPrintLine(f); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
801 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
802 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
803 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
804 fprintf(f, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
805 "\n" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
806 "NC = Not Connected\n" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
807 "RSVD = Reserved\n" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
808 "ROM/WT = RAM under 'write-through' ROM\n" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
809 "\n" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
810 ); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
811 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
812 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
813 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
814 /* |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
815 * The main program |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
816 */ |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
817 int main(int argc, char *argv[]) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
818 { |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
819 FILE *outFile = NULL; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
820 BOOL hasOverlaps; |
2554 | 821 int res = DMERR_OK, startAddr, endAddr, dataSize, totalSize; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
822 |
1677
c2ad6c0e4975
Bump copyright year and version.
Matti Hamalainen <ccr@tnsp.org>
parents:
1676
diff
changeset
|
823 dmInitProg("objlink", "Simple file-linker", "0.82", NULL, NULL); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
824 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
825 // Parse arguments |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
826 if (!dmArgsProcess(argc, argv, optList, optListN, |
860
daebbf28953d
The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
830
diff
changeset
|
827 argHandleOpt, NULL, OPTH_BAILOUT)) |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
828 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
829 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
830 if (nsrcFiles < 1) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
831 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
832 dmErrorMsg("Nothing to do. (try --help)\n"); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
833 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
834 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
835 |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
836 // Warn about overlaps if enabled |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
837 if (optAllowOverlap) |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
838 dmMsg(-1, "WARNING: Overlapping data has been allowed!\n"); |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
839 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
840 // Allocate memory |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
841 memModel = &memoryModels[optMemModel]; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
842 dmMsg(1, "Using memory model #%d '%s', %d bytes.\n", |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
843 optMemModel, memModel->name, memModel->size); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
844 |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
845 if ((memory = (Uint8 *) dmMalloc(memModel->size + 32)) == NULL) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
846 { |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
847 dmErrorMsg("Could not allocate memory for memory model!\n"); |
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
848 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
849 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
850 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
851 // Initialize memory |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
852 dmMsg(1, "Initializing memory with "); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
853 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
854 if (optInitValueType == 1 || optInitValue <= 0xff) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
855 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
856 dmPrint(1, "BYTE 0x%.2x\n", optInitValue); |
2414
69a5af2eb1ea
Remove useless dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents:
2412
diff
changeset
|
857 memset(memory, optInitValue, memModel->size); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
858 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
859 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
860 if (optInitValueType == 2 || optInitValue <= 0xffff) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
861 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
862 uint16_t *mp = (uint16_t *) memory; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
863 dmPrint(1, "WORD 0x%.4x\n", optInitValue); |
1673 | 864 for (int i = memModel->size / sizeof(*mp); i; i--) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
865 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
866 *mp++ = optInitValue; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
867 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
868 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
869 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
870 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
871 Uint32 *mp = (Uint32 *) memory; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
872 dmPrint(1, "DWORD 0x%.8x\n", optInitValue); |
1673 | 873 for (int i = memModel->size / sizeof(*mp); i; i--) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
874 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
875 *mp++ = optInitValue; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
876 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
877 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
878 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
879 // Load the datafiles |
1673 | 880 for (int i = 0; i < nsrcFiles; i++) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
881 switch (srcFiles[i].type) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
882 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
883 case STYPE_RAW: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
884 dmLoadRAW(srcFiles[i].filename, srcFiles[i].addr); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
885 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
886 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
887 case STYPE_PRG: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
888 dmLoadPRG(srcFiles[i].filename, FALSE, 0); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
889 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
890 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
891 case STYPE_PRGA: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
892 dmLoadPRG(srcFiles[i].filename, TRUE, srcFiles[i].addr); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
893 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
894 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
895 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
896 // Add memory model blocks |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
897 dmMsg(1, "Applying memory model restrictions...\n"); |
1673 | 898 for (int i = 0; i < memModel->nmemBlocks; i++) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
899 { |
2554 | 900 if ((res = dmReserveMemBlock( |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
901 memModel->memBlocks[i].start, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
902 memModel->memBlocks[i].end, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
903 memModel->memBlocks[i].name, |
2554 | 904 memModel->memBlocks[i].type)) != DMERR_OK) |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
905 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
906 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
907 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
908 // Sort the blocks |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
909 qsort(memBlocks, nmemBlocks, sizeof(DMMemBlock), dmCompareMemBlock); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
910 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
911 // Check for overlapping conflicts |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
912 hasOverlaps = FALSE; |
1673 | 913 for (int i = 0; i < nmemBlocks; i++) |
914 for (int j = 0; j < nmemBlocks; j++) | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
915 if (j != i && memBlocks[i].type == MTYPE_RES) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
916 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
917 DMMemBlock *mbi = &memBlocks[i], |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
918 *mbj = &memBlocks[j]; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
919 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
920 // Check for per-file conflicts |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
921 if ((mbj->start >= mbi->start && mbj->start <= mbi->end) || |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
922 (mbj->end >= mbi->start && mbj->end <= mbi->end)) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
923 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
924 dmPrint(1, "* '%s' and '%s' overlap ($%.4x-$%.4x vs $%.4x-$%.4x)\n", |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
925 mbi->name, mbj->name, mbi->start, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
926 mbi->end, mbj->start, mbj->end); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
927 hasOverlaps = TRUE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
928 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
929 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
930 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
931 if (!optAllowOverlap && hasOverlaps) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
932 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
933 dmErrorMsg("Error occured, overlaps not allowed.\n"); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
934 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
935 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
936 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
937 // Find out start and end-addresses |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
938 startAddr = memModel->size; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
939 totalSize = endAddr = 0; |
1673 | 940 for (int i = 0; i < nmemBlocks; i++) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
941 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
942 DMMemBlock *mbi = &memBlocks[i]; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
943 if (mbi->type == MTYPE_RES) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
944 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
945 if (mbi->start < startAddr) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
946 startAddr = mbi->start; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
947 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
948 if (mbi->end > endAddr) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
949 endAddr = mbi->end; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
950 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
951 totalSize += (mbi->end - mbi->start + 1); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
952 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
953 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
954 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
955 if (startAddr >= memModel->size || endAddr < startAddr) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
956 { |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
957 dmErrorMsg("Invalid saveblock addresses (start=$%.4x, end=$%.4x)!\n", |
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
958 startAddr, endAddr); |
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
959 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
960 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
961 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
962 // Output linkfile |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
963 if (optLinkFileName) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
964 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
965 dmMsg(1, "Writing linkfile to '%s'\n", optLinkFileName); |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
966 if ((outFile = fopen(optLinkFileName, "wb")) == NULL) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
967 { |
2554 | 968 res = dmGetErrno(); |
969 dmErrorMsg("Error creating file '%s': %s.\n", | |
970 optLinkFileName, dmErrorStr(res)); | |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
971 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
972 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
973 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
974 switch (optLinkFileFormat) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
975 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
976 case FMT_GENERIC: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
977 default: |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
978 fprintf(outFile, "; Definitions generated by %s v%s\n", |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
979 dmProgName, dmProgVersion); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
980 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
981 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
982 |
1673 | 983 for (int i = 0; i < nmemBlocks; i++) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
984 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
985 DMMemBlock *mbi = &memBlocks[i]; |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
986 outputLinkData(outFile, mbi->name, mbi->start, mbi->end); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
987 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
988 |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
989 fclose(outFile); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
990 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
991 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
992 // Show some information |
485
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
993 if (optCropOutput) |
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
994 { |
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
995 startAddr = optCropStart; |
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
996 endAddr = optCropEnd; |
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
997 } |
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
998 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
999 dataSize = endAddr - startAddr + 1; |
485
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
1000 |
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
1001 if (dataSize - totalSize > 0) |
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
1002 { |
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
1003 dmMsg(1, "Total of %d/$%x bytes unused(?) areas.\n", |
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
1004 dataSize - totalSize, dataSize - totalSize); |
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
1005 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1006 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1007 dmMsg(1, "Writing $%.4x - $%.4x (%d/$%x bytes) ", |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1008 startAddr, endAddr, dataSize, dataSize); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1009 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1010 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1011 // Open the destination file |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1012 if (optDestName == NULL) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1013 { |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1014 outFile = stdout; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1015 dmPrint(1, "...\n"); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1016 } |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1017 else if ((outFile = fopen(optDestName, "wb")) == NULL) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1018 { |
2554 | 1019 res = dmGetErrno(); |
1020 dmErrorMsg("Error creating output file '%s': %s.\n", | |
1021 optDestName, dmErrorStr(res)); | |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1022 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1023 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1024 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1025 dmPrint(1, "to '%s'\n", optDestName); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1026 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1027 // Save loading address |
501
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
1028 if (optLoadAddress >= 0) |
504
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1029 { |
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1030 dmMsg(1, "Using specified loading address $%.4x\n", optLoadAddress); |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1031 dm_fwrite_le16(outFile, optLoadAddress); |
504
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1032 } |
501
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
1033 else |
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
1034 if (optLoadAddress == LA_AUTO) |
504
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1035 { |
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1036 dmMsg(1, "Using automatic loading address $%.4x\n", startAddr); |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1037 dm_fwrite_le16(outFile, startAddr); |
504
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1038 } |
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1039 else |
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1040 { |
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1041 dmMsg(1, "Writing raw output, without loading address.\n"); |
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1042 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1043 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1044 // Save the data |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1045 if (fwrite(&memory[startAddr], dataSize, 1, outFile) < 1) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1046 { |
2554 | 1047 res = dmGetErrno(); |
1048 dmErrorMsg( | |
1049 "Error writing to file: %s.\n", | |
1050 dmErrorStr(res)); | |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1051 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1052 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1053 |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1054 // Describe the memory layout |
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1055 if (optDescribe) |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1056 dmDescribeMemory(outFile != stdout ? stdout : stderr); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1057 |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1058 out: |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1059 if (outFile != NULL && outFile != stdout) |
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1060 fclose(outFile); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1061 |
2554 | 1062 return res; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1063 } |