Mercurial > hg > dmlib
annotate tools/objlink.c @ 2564:2cf4e995b50c
Improve error checking.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 28 Feb 2022 10:18:38 +0200 |
parents | 8dd81ec802f4 |
children | d56a0e86067a |
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 |
2556 | 4 * (C) Copyright 2002-2022 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 { |
2563
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
31 int noverlaps; |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
32 int overlaps[SET_MAX_FILENAMES]; |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
33 } DMMemBlockOverlap; |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
34 |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
35 |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
36 typedef struct |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
37 { |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 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
|
39 char *desc; |
2553 | 40 int size; // Total addressable memory size |
41 int nmemBlocks; // Defined memory areas | |
1681 | 42 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
|
43 } DMMemModel; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 |
2411 | 45 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 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
|
47 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 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
|
49 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
|
50 int placement; |
864 | 51 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
|
52 } DMSourceFile; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 |
2411 | 54 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 // 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
|
56 enum |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 }; |
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 // 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
|
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 PLACE_STATIC = 1, // Already known |
2553 | 67 PLACE_ARGUMENT, // Commandline argument |
68 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
|
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 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
|
74 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
|
75 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
|
76 }; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 enum |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 MTYPE_NONE = 0, |
2555
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
81 MTYPE_ROM, // ROM |
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
82 MTYPE_WT, // Write to RAM through ROM |
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
83 MTYPE_IO, // I/O lines |
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
84 MTYPE_RES // RESERVED |
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 }; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
86 |
501
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
87 enum |
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
88 { |
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
89 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
|
90 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
|
91 }; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 |
2411 | 93 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 /* 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
|
95 */ |
2411 | 96 const DMMemModel memoryModels[] = |
97 { | |
98 { "C64 unrestricted", "$01 = $34", | |
99 64 * 1024, | |
100 0, | |
101 { | |
2555
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
102 { 0x0000, 0x0000, 0 , NULL , 0 } |
2411 | 103 } |
104 }, | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 |
2411 | 106 { "C64 normal (IO+Basic+Kernal)", "$01 = $37", |
107 64 * 1024, | |
108 3, | |
109 { | |
2555
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
110 { 0xA000, 0xBFFF, MTYPE_WT , "Basic ROM" , PLACE_STATIC }, |
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
111 { 0xD000, 0xDFFF, MTYPE_IO , "I/O" , PLACE_STATIC }, |
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
112 { 0xE000, 0xFFFF, MTYPE_WT , "Kernal ROM" , PLACE_STATIC }, |
2411 | 113 } |
114 }, | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 |
2411 | 116 { "C64 modified (IO+Kernal)", "$01 = $36", |
117 64 * 1024, | |
118 2, | |
119 { | |
2555
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
120 { 0xD000, 0xDFFF, MTYPE_IO , "I/O" , PLACE_STATIC }, |
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
121 { 0xE000, 0xFFFF, MTYPE_WT , "Kernal ROM" , PLACE_STATIC }, |
2411 | 122 } |
123 }, | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 |
2411 | 125 { "C64 modified (IO only)", "$01 = $35", |
126 64 * 1024, | |
127 1, | |
128 { | |
2555
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
129 { 0xD000, 0xDFFF, MTYPE_IO , "I/O" , PLACE_STATIC }, |
2411 | 130 } |
131 }, | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 |
2411 | 133 { "C64 modified (Char+Kernal+Basic)", "$01 = $33", |
134 64 * 1024, | |
135 3, | |
136 { | |
2555
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
137 { 0xA000, 0xBFFF, MTYPE_WT , "Basic ROM" , PLACE_STATIC }, |
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
138 { 0xD000, 0xDFFF, MTYPE_ROM , "Char ROM" , PLACE_STATIC }, |
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
139 { 0xE000, 0xFFFF, MTYPE_WT , "Kernal ROM" , PLACE_STATIC }, |
2411 | 140 } |
141 }, | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 }; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 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
|
145 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 /* 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
|
148 */ |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 int nsrcFiles = 0; // Number of source files |
1681 | 150 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
|
151 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 int nmemBlocks = 0; |
1681 | 153 DMMemBlock memBlocks[SET_MAX_FILENAMES]; |
2563
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
154 DMMemBlockOverlap memBlockOverlaps[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
|
155 |
2411 | 156 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
|
157 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
|
158 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
|
159 BOOL optDescribe = FALSE, |
2411 | 160 optAllowOverlap = FALSE, |
161 optCropOutput = FALSE; | |
162 unsigned int optCropStart, optCropEnd; | |
163 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
|
164 int optInitValueType = 1; |
2411 | 165 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
|
166 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
|
167 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
|
168 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
|
169 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 /* Arguments |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
172 */ |
860
daebbf28953d
The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
830
diff
changeset
|
173 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
|
174 { |
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
|
175 { 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
|
176 { 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
|
177 { 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
|
178 |
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 { 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
|
180 { 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
|
181 { 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
|
182 { 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
|
183 { 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
|
184 { 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
|
185 { 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
|
186 { 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
|
187 { 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
|
188 { 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
|
189 { 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
|
190 { 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
|
191 }; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 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
|
194 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 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
|
197 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 dmPrintBanner(stdout, dmProgName, "[options]"); |
2402
b7cd5dd0b82e
Merge one more change from th-libs args processing.
Matti Hamalainen <ccr@tnsp.org>
parents:
2384
diff
changeset
|
199 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
|
200 |
2553 | 201 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
|
202 "\n" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
203 "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
|
204 "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
|
205 "\n" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 "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
|
207 |
1678 | 208 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
|
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 const DMMemModel *m = &memoryModels[i]; |
2553 | 211 fprintf(stdout, |
212 " %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
|
213 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
|
214 } |
2555
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
215 |
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
216 fprintf(stdout, |
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
217 "\n" |
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
218 "Memory block types:\n" |
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
219 " NC = Not Connected\n" |
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
220 " RSVD = Reserved\n" |
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
221 " WT = RAM under 'write-through' ROM\n" |
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
222 "\n" |
6249aa494e83
Rename "ROM/WT" blocks to just "WT", move the description to --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2554
diff
changeset
|
223 ); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
225 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
226 |
2559 | 227 off_t dmGetFileSize(FILE *fh) |
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 { |
2559 | 229 off_t len, pos = ftell(fh); |
230 fseeko(fh, 0, SEEK_END); | |
231 len = ftell(fh); | |
232 fseek(fh, pos, SEEK_SET); | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 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
|
234 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
235 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
236 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 /* 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
|
238 */ |
2554 | 239 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
|
240 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
241 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
|
242 { |
2554 | 243 return dmError(DMERR_INVALID_ARGS, |
244 "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
|
245 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
|
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 |
1681 | 248 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
|
249 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
250 memBlocks[nmemBlocks].start = startAddr; |
497
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
251 memBlocks[nmemBlocks].end = endAddr; |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
252 memBlocks[nmemBlocks].name = dm_strdup(blockName); |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
253 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
|
254 nmemBlocks++; |
2554 | 255 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
|
256 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
257 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
258 { |
2554 | 259 return dmError(DMERR_BOUNDS, |
260 "Maximum number of memBlock definitions (%d) exceeded!\n", | |
1681 | 261 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
|
262 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
263 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
264 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
265 |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
266 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
|
267 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
268 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
|
269 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
|
270 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
271 |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
272 |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
864
diff
changeset
|
273 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
|
274 { |
497
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
275 char sectMode, *sep, *str, *namesep; |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
864
diff
changeset
|
276 unsigned int tmpi; |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
277 BOOL res = FALSE; |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
278 |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
279 // Define reserved section |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
280 // 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
|
281 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
|
282 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
283 dmErrorMsg("Could not allocate temporary string!\n"); |
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 } |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
286 |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
287 // Get start address |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
288 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
|
289 (sep = strchr(str, ':')) == NULL) |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
290 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
291 dmErrorMsg("Section definition '%s' invalid.\n", arg); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
292 goto out; |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
293 } |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
294 sectMode = *sep; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
295 *sep = 0; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
296 |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
297 // Get value |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1681
diff
changeset
|
298 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
|
299 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
300 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
|
301 goto out; |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
302 } |
1238 | 303 |
497
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
304 // Check for name |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
305 namesep = strchr(sep + 1, ','); |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
306 if (canHasName && namesep != NULL) |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
307 { |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
308 *namesep = 0; |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
309 namesep++; |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
310 if (*namesep == 0) |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
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 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
|
313 arg); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
314 goto out; |
497
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
315 } |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
316 *sectName = dm_strdup(namesep); |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
317 } |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
318 else |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
319 if (namesep != NULL) |
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
320 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
321 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
|
322 arg, namesep); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
323 goto out; |
497
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
324 } |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
325 |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
326 // 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
|
327 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
|
328 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
329 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
|
330 sectMode == '-' ? "end address" : "length", |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
331 sep + 1, arg); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
332 goto out; |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
333 } |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
334 |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
335 if (sectMode == ':') |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
336 { |
497
b02f1bfce53b
Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
337 *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
|
338 } |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
339 else |
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 if (tmpi < *sectStart) |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
342 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
343 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
|
344 arg); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
345 goto out; |
484
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 *sectEnd = tmpi; |
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 |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
350 res = TRUE; |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
351 |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
352 out: |
484
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
353 dmFree(str); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
354 return res; |
484
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 |
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 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
|
359 { |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
864
diff
changeset
|
360 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
|
361 BOOL hasAddr = FALSE; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
362 char *sep; |
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 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
|
365 { |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
366 *sep = 0; |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1681
diff
changeset
|
367 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
|
368 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
369 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
|
370 desc, sep + 1, arg); |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
371 return FALSE; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
372 } |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
373 hasAddr = TRUE; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
374 } |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
375 else |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
376 if (requireAddr) |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
377 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
378 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
|
379 return FALSE; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
380 } |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
381 |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
382 srcFiles[nsrcFiles].filename = arg; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
383 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
|
384 srcFiles[nsrcFiles].addr = tmpi; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
385 nsrcFiles++; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
386 return TRUE; |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
387 } |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
388 |
81b92a0e754b
Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
389 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
390 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
|
391 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
392 |
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
|
393 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
|
394 { |
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 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
|
396 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
|
397 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
|
398 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
|
399 |
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
|
400 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
|
401 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
|
402 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
|
403 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
|
404 |
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
|
405 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
|
406 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
|
407 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
|
408 |
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
|
409 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
|
410 // 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
|
411 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
|
412 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
|
413 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
|
414 |
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
|
415 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
|
416 // 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
|
417 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
|
418 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
|
419 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
|
420 |
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
|
421 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
|
422 { |
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 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
|
424 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
|
425 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
|
426 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
|
427 |
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
|
428 // 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
|
429 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
|
430 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
|
431 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
|
432 |
2554 | 433 if (dmReserveMemBlock(sectStart, sectEnd, sectName, MTYPE_RES) != DMERR_OK) |
1238 | 434 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
|
435 } |
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
|
436 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
|
437 |
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 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
|
439 // 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
|
440 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
|
441 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
|
442 |
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 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
|
444 // 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
|
445 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
|
446 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
|
447 |
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
|
448 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
|
449 // 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
|
450 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
|
451 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
|
452 { |
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 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
|
454 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
|
455 } |
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 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
|
457 |
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
|
458 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
|
459 // 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
|
460 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
|
461 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
|
462 |
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
|
463 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
|
464 // 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
|
465 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
|
466 { |
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 '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
|
468 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
|
469 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
|
470 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
|
471 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
|
472 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
|
473 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
|
474 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
|
475 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
|
476 |
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
|
477 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
|
478 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
|
479 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
|
480 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
|
481 } |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
482 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
|
483 |
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
|
484 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
|
485 // 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
|
486 { |
2512 | 487 char *p; |
488 unsigned int tmpi; | |
489 | |
490 optInitValueType = 1; | |
491 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
|
492 { |
2512 | 493 *p = 0; |
494 switch (tolower(p[1])) | |
495 { | |
496 case 'b': optInitValueType = 1; break; | |
497 case 'w': optInitValueType = 2; break; | |
498 case 'd': optInitValueType = 4; break; | |
499 default: | |
500 dmErrorMsg("Invalid init value type '%c' specified for '%s'.\n", | |
501 p[1], optArg); | |
502 return FALSE; | |
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 } |
2512 | 505 if (!dmGetIntVal(optArg, &tmpi, NULL)) |
506 { | |
507 dmErrorMsg("Invalid initvalue '%s'.\n", optArg); | |
508 return FALSE; | |
509 } | |
510 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
|
511 } |
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 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
|
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 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
|
515 // 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
|
516 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
|
517 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
|
518 |
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 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
|
520 { |
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
|
521 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
|
522 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
|
523 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
|
524 |
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 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
|
526 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
|
527 "($%" 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
|
528 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
|
529 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
|
530 |
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 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
|
532 } |
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
|
533 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
|
534 |
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
|
535 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
|
536 // 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
|
537 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
|
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 = 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
|
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 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
|
542 { |
2512 | 543 unsigned int tmpi; |
544 | |
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
|
545 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
|
546 { |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
547 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
|
548 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
|
549 } |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
550 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
|
551 { |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
552 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
|
553 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
|
554 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
|
555 } |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
556 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
|
557 } |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
558 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
|
559 |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
560 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
|
561 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
|
562 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
|
563 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
564 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
565 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
|
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 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
568 |
1676 | 569 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
|
570 { |
1674 | 571 FILE *fh; |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
572 int dataSize, loadAddr, endAddr, res = DMERR_OK; |
486 | 573 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
|
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 // Open the input file |
1674 | 576 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
|
577 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
578 res = dmGetErrno(); |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
579 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
|
580 filename, res, dmErrorStr(res)); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
581 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
|
582 } |
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 // Get filesize |
1674 | 585 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
|
586 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
587 res = dmGetErrno(); |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
588 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
|
589 filename, res, dmErrorStr(res)); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
590 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
|
591 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
592 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
593 // Get loading address |
1674 | 594 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
|
595 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
596 res = dmGetErrno(); |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
597 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
|
598 filename, res, dmErrorStr(res)); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
599 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
|
600 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
601 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
602 // Show information |
486 | 603 loadAddr = forceAddr ? destAddr : tmpAddr; |
604 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
|
605 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
606 dmPrint(1, "* Loading '%s', %s at $%.4x-$%.4x", |
486 | 607 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
|
608 |
486 | 609 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
|
610 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
611 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
|
612 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
|
613 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
|
614 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
615 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
616 // Load data |
1674 | 617 if (fread(&memory[loadAddr], dataSize, 1, fh) < 1) |
486 | 618 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
619 res = dmGetErrno(); |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
620 dmPrint(1, " .. Error #%d: %s.\n", |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
621 res, dmErrorStr(res)); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
622 goto out; |
486 | 623 } |
624 | |
625 dmPrint(1, " .. OK\n"); | |
626 | |
627 // Add to list of blocks | |
2554 | 628 if ((res = dmReserveMemBlock(loadAddr, endAddr, filename, MTYPE_RES)) != DMERR_OK) |
629 goto out; | |
486 | 630 |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
631 out: |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
632 if (fh != NULL) |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
633 fclose(fh); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
634 |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
635 return res; |
486 | 636 } |
637 | |
638 | |
864 | 639 int dmLoadRAW(const char *filename, const int destAddr) |
486 | 640 { |
1674 | 641 FILE *fh; |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
642 int dataSize, endAddr, res = DMERR_OK; |
486 | 643 |
644 // Open the input file | |
1674 | 645 if ((fh = fopen(filename, "rb")) == NULL) |
486 | 646 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
647 res = dmGetErrno(); |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
648 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
|
649 filename, res, dmErrorStr(res)); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
650 goto out; |
486 | 651 } |
652 | |
653 // Get filesize | |
1674 | 654 if ((dataSize = dmGetFileSize(fh)) < 0) |
486 | 655 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
656 res = dmError(DMERR_FREAD, |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
657 "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
|
658 goto out; |
486 | 659 } |
660 | |
661 // Show information | |
662 endAddr = destAddr + dataSize - 1; | |
663 dmPrint(1, "* Loading '%s', RAW at $%.4x-$%.4x", | |
664 filename, destAddr, endAddr); | |
665 | |
666 if (endAddr >= memModel->size) | |
667 { | |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
668 res = DMERR_BOUNDS; |
486 | 669 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
|
670 goto out; |
486 | 671 } |
672 | |
673 // Load data | |
1674 | 674 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
|
675 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
676 res = dmGetErrno(); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
677 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
|
678 res, dmErrorStr(res)); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
679 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
|
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 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
682 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
|
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 // Add info to list |
2554 | 685 if ((res = dmReserveMemBlock(destAddr, endAddr, filename, MTYPE_RES)) != DMERR_OK) |
686 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
|
687 |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
688 out: |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
689 if (fh != NULL) |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
690 fclose(fh); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
691 |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
692 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
|
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 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
695 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
696 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
|
697 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
698 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
|
699 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
|
700 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
701 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
|
702 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
703 // Create label name from filename |
2554 | 704 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
|
705 { |
2554 | 706 return dmError(DMERR_MALLOC, |
707 "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
|
708 blockName); |
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 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
|
712 s = (t + 1); |
1678 | 713 else |
714 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
|
715 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
|
716 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
717 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
|
718 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
719 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
|
720 *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
|
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 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
|
723 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
724 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
|
725 *t = '_'; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
726 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
727 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
728 // 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
|
729 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
|
730 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
731 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
|
732 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
|
733 break; |
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 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
|
736 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
|
737 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
738 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
739 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
|
740 default: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
741 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
|
742 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
|
743 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
|
744 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
745 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
746 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
747 dmFree(tmpStr); |
2554 | 748 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
|
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 |
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 /* 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
|
753 */ |
2560
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
754 #define BOX_WIDTH 60 |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
755 #define TO_STR1(x) #x |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
756 #define TO_STR(x) TO_STR1(x) |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
757 |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
758 void memPrintLine(FILE *fh) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
759 { |
2560
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
760 fputs(" +", fh); |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
761 for (int i = 0; i < BOX_WIDTH + 2; i++) |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
762 fputc('-', fh); |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
763 fputs("+\n", fh); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
764 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
765 |
2560
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
766 void memPrintEmpty(FILE *fh, const 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
|
767 { |
1678 | 768 for (int i = 0; i < n; i++) |
2560
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
769 { |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
770 fputs(" | ", fh); |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
771 for (int i = 0; i < BOX_WIDTH; i++) |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
772 fputc(' ', fh); |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
773 fputs(" |\n", fh); |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
774 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
775 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
776 |
2560
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
777 void memPrintBox(FILE *fh, const int bsize, const int bstart, const int bend, const char *bdesc) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
778 { |
2560
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
779 int bksize = bsize / (1024 * 2); |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
780 if (bksize > 1) memPrintEmpty(fh, bksize); |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
781 fprintf(fh, "$%.4x - $%.4x | %-" TO_STR(BOX_WIDTH) "s |\n", bstart, bend, bdesc); |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
782 if (bksize > 1) memPrintEmpty(fh, bksize); |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
783 memPrintLine(fh); |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
784 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
785 |
2560
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
786 void dmDescribeMemory(FILE *fh) |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
787 { |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
788 DMMemBlock *bprev = NULL; |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
789 |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
790 memPrintLine(fh); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
791 |
1678 | 792 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
|
793 { |
2560
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
794 DMMemBlock *bcurr = &memBlocks[i]; |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
795 char bdesc[128]; |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
796 const char *btype; |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
797 int bsize; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
798 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
799 // Check for empty, unreserved areas |
2560
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
800 if (bprev != NULL && (bsize = (bcurr->start - 1) - (bprev->end + 1) + 1) > 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
|
801 { |
2560
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
802 snprintf(bdesc, sizeof(bdesc), "EMPTY (%d)", bsize); |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
803 memPrintBox(fh, bsize, bprev->end + 1, bcurr->start - 1, bdesc); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
804 } |
2560
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
805 bprev = bcurr; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
806 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
807 // Print current block |
2560
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
808 switch (bcurr->type) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
809 { |
2560
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
810 case MTYPE_NONE: btype = "N/A (NC)"; break; |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
811 case MTYPE_ROM: btype = "ROM"; break; |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
812 case MTYPE_WT: btype = "WT"; break; |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
813 case MTYPE_IO: btype = "I/O"; break; |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
814 case MTYPE_RES: btype = "RSVD"; break; |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
815 default: btype = "????"; 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
|
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 |
2560
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
818 bsize = bcurr->end - bcurr->start + 1; |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
819 snprintf(bdesc, sizeof(bdesc), "%.40s (%s, %d)", bcurr->name, btype, bsize); |
ac2e60f4bfc3
Improve block description output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2559
diff
changeset
|
820 memPrintBox(fh, bsize, bcurr->start, bcurr->end, bdesc); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
821 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
822 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
823 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
824 |
2564 | 825 int dmAddOverlap(DMMemBlockOverlap *olp, const int index) |
826 { | |
827 if (olp->noverlaps < SET_MAX_FILENAMES) | |
828 { | |
829 olp->overlaps[olp->noverlaps++] = index; | |
830 return DMERR_OK; | |
831 } | |
832 else | |
833 { | |
834 return dmError(DMERR_BOUNDS, | |
835 "Too many memory block overlaps (%d >= %d).\n", | |
836 olp->noverlaps, SET_MAX_FILENAMES); | |
837 } | |
838 } | |
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 /* |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
841 * 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
|
842 */ |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
843 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
|
844 { |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
845 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
|
846 BOOL hasOverlaps; |
2554 | 847 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
|
848 |
2558 | 849 dmInitProg("objlink", "Simple file-linker", "0.83", 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
|
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 // 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
|
852 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
|
853 argHandleOpt, NULL, OPTH_BAILOUT)) |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
854 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
|
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 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
|
857 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
858 dmErrorMsg("Nothing to do. (try --help)\n"); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
859 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
|
860 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
861 |
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
|
862 // 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
|
863 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
|
864 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
|
865 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
866 // 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
|
867 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
|
868 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
|
869 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
|
870 |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
871 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
|
872 { |
2564 | 873 res = dmError(DMERR_MALLOC, |
874 "Could not allocate memory for memory model!\n"); | |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
875 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
|
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 // 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
|
879 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
|
880 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
881 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
|
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 dmPrint(1, "BYTE 0x%.2x\n", optInitValue); |
2414
69a5af2eb1ea
Remove useless dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents:
2412
diff
changeset
|
884 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
|
885 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
886 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
887 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
|
888 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
889 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
|
890 dmPrint(1, "WORD 0x%.4x\n", optInitValue); |
1673 | 891 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
|
892 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
893 *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
|
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 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
897 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
898 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
|
899 dmPrint(1, "DWORD 0x%.8x\n", optInitValue); |
1673 | 900 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
|
901 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
902 *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
|
903 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
904 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
905 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
906 // Load the datafiles |
1673 | 907 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
|
908 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
|
909 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
910 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
|
911 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
|
912 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
913 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
914 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
|
915 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
|
916 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
917 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
918 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
|
919 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
|
920 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
921 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
922 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
923 // 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
|
924 dmMsg(1, "Applying memory model restrictions...\n"); |
1673 | 925 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
|
926 { |
2554 | 927 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
|
928 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
|
929 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
|
930 memModel->memBlocks[i].name, |
2554 | 931 memModel->memBlocks[i].type)) != DMERR_OK) |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
932 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
|
933 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
934 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
935 // Sort the blocks |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
936 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
|
937 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
938 // 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
|
939 hasOverlaps = FALSE; |
2561 | 940 for (int bk1 = 0; bk1 < nmemBlocks; bk1++) |
941 for (int bk2 = 0; bk2 < nmemBlocks; bk2++) | |
942 if (bk1 != bk2) | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
943 { |
2563
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
944 DMMemBlockOverlap |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
945 *olp1 = &memBlockOverlaps[bk1], |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
946 *olp2 = &memBlockOverlaps[bk2]; |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
947 DMMemBlock |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
948 *mb1 = &memBlocks[bk1], |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
949 *mb2 = &memBlocks[bk2]; |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
950 BOOL found = FALSE; |
2561 | 951 |
952 if (mb1->type != MTYPE_RES) | |
953 continue; | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
954 |
2563
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
955 for (int no = 0; no < olp1->noverlaps; no++) |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
956 { |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
957 if (olp1->overlaps[no] == bk2) |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
958 { |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
959 found = TRUE; |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
960 break; |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
961 } |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
962 } |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
963 if (found) |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
964 continue; |
8dd81ec802f4
Prevent reporting same cross-overlap areas two times.
Matti Hamalainen <ccr@tnsp.org>
parents:
2562
diff
changeset
|
965 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
966 // Check for per-file conflicts |
2561 | 967 if ((mb2->start >= mb1->start && mb2->start <= mb1->end) || |
968 (mb2->end >= mb1->start && mb2->end <= mb1->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
|
969 { |
2562 | 970 dmPrint(-1, "* '%s' and '%s' overlap ($%.4x-$%.4x vs $%.4x-$%.4x)\n", |
2561 | 971 mb1->name, mb2->name, mb1->start, |
972 mb1->end, mb2->start, mb2->end); | |
973 | |
2564 | 974 if ((res = dmAddOverlap(olp1, bk2)) != DMERR_OK || |
975 (res = dmAddOverlap(olp2, bk1)) != DMERR_OK) | |
976 goto out; | |
977 | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
978 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
|
979 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
980 } |
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 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
|
983 { |
2564 | 984 res = dmError(DMERR_BOUNDS, |
985 "Error occured, overlaps not allowed.\n"); | |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
986 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
|
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 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
989 // 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
|
990 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
|
991 totalSize = endAddr = 0; |
1673 | 992 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
|
993 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
994 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
|
995 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
|
996 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
997 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
|
998 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
|
999 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1000 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
|
1001 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
|
1002 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1003 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
|
1004 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1005 } |
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 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
|
1008 { |
2564 | 1009 res = dmError(DMERR_BOUNDS, |
1010 "Invalid saveblock addresses (start=$%.4x, end=$%.4x)!\n", | |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1011 startAddr, endAddr); |
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1012 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
|
1013 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1014 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1015 // 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
|
1016 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
|
1017 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1018 dmMsg(1, "Writing linkfile to '%s'\n", optLinkFileName); |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1019 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
|
1020 { |
2554 | 1021 res = dmGetErrno(); |
1022 dmErrorMsg("Error creating file '%s': %s.\n", | |
1023 optLinkFileName, dmErrorStr(res)); | |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1024 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
|
1025 } |
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 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
|
1028 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1029 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
|
1030 default: |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1031 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
|
1032 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
|
1033 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1034 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1035 |
1673 | 1036 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
|
1037 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1038 DMMemBlock *mbi = &memBlocks[i]; |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1039 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
|
1040 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1041 |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1042 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
|
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 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1045 // 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
|
1046 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
|
1047 { |
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
1048 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
|
1049 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
|
1050 } |
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
1051 |
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 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
|
1053 |
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
1054 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
|
1055 { |
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
1056 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
|
1057 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
|
1058 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1059 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1060 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
|
1061 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
|
1062 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1063 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1064 // 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
|
1065 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
|
1066 { |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1067 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
|
1068 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
|
1069 } |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1070 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
|
1071 { |
2554 | 1072 res = dmGetErrno(); |
1073 dmErrorMsg("Error creating output file '%s': %s.\n", | |
1074 optDestName, dmErrorStr(res)); | |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1075 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
|
1076 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1077 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1078 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
|
1079 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1080 // 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
|
1081 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
|
1082 { |
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1083 dmMsg(1, "Using specified loading address $%.4x\n", optLoadAddress); |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1084 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
|
1085 } |
501
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
1086 else |
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
1087 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
|
1088 { |
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1089 dmMsg(1, "Using automatic loading address $%.4x\n", startAddr); |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1090 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
|
1091 } |
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1092 else |
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1093 { |
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1094 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
|
1095 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1096 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1097 // Save the data |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1098 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
|
1099 { |
2554 | 1100 res = dmGetErrno(); |
1101 dmErrorMsg( | |
1102 "Error writing to file: %s.\n", | |
1103 dmErrorStr(res)); | |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1104 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
|
1105 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1106 |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1107 // Describe the memory layout |
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1108 if (optDescribe) |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1109 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
|
1110 |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1111 out: |
2412
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1112 if (outFile != NULL && outFile != stdout) |
203b0fbb05d3
Make default verbosity quieter.
Matti Hamalainen <ccr@tnsp.org>
parents:
2411
diff
changeset
|
1113 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
|
1114 |
2554 | 1115 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
|
1116 } |