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