Mercurial > hg > dmlib
annotate tools/objlink.c @ 2384:36edd316184a
Fix some format strings to use proper PRI*_SIZE_T where necessary.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 09 Jan 2020 15:20:23 +0200 |
parents | e3f0eaf23f4f |
children | b7cd5dd0b82e |
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; |
2384
36edd316184a
Fix some format strings to use proper PRI*_SIZE_T where necessary.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
478 dmMsg(1, "Cutting output to $%.4x - $%.4x " |
36edd316184a
Fix some format strings to use proper PRI*_SIZE_T where necessary.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
479 "($%" DM_PRIx_SIZE_T ", %" DM_PRIu_SIZE_T " bytes)\n", |
36edd316184a
Fix some format strings to use proper PRI*_SIZE_T where necessary.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
480 optCropStart, optCropEnd, |
36edd316184a
Fix some format strings to use proper PRI*_SIZE_T where necessary.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
481 cropLen, cropLen); |
485
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 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
|
484 } |
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
485 break; |
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
486 |
501
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
487 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
|
488 // 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
|
489 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
|
490 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
|
491 else |
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
492 { |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1681
diff
changeset
|
493 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
|
494 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
495 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
|
496 return FALSE; |
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
497 } |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
864
diff
changeset
|
498 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
|
499 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
500 dmErrorMsg("Invalid or insane loading address %d/$%x!\n", |
2384
36edd316184a
Fix some format strings to use proper PRI*_SIZE_T where necessary.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
501 tmpi, 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
|
502 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
|
503 } |
504
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
504 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
|
505 } |
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
506 break; |
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
507 |
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 default: |
2183
e3f0eaf23f4f
Change the error message for unimplemented option argument.
Matti Hamalainen <ccr@tnsp.org>
parents:
2012
diff
changeset
|
509 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
|
510 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
|
511 } |
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 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
|
514 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
515 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
516 |
1676 | 517 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
|
518 { |
1674 | 519 FILE *fh; |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
520 int dataSize, loadAddr, endAddr, res = DMERR_OK; |
486 | 521 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
|
522 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
523 // Open the input file |
1674 | 524 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
|
525 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
526 res = dmGetErrno(); |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
527 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
|
528 filename, res, dmErrorStr(res)); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
529 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
|
530 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
531 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
532 // Get filesize |
1674 | 533 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
|
534 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
535 res = dmGetErrno(); |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
536 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
|
537 filename, res, dmErrorStr(res)); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
538 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
|
539 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
540 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
541 // Get loading address |
1674 | 542 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
|
543 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
544 res = dmGetErrno(); |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
545 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
|
546 filename, res, dmErrorStr(res)); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
547 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
|
548 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
549 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
550 // Show information |
486 | 551 loadAddr = forceAddr ? destAddr : tmpAddr; |
552 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
|
553 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
554 dmPrint(1, "* Loading '%s', %s at $%.4x-$%.4x", |
486 | 555 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
|
556 |
486 | 557 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
|
558 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
559 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
|
560 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
|
561 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
|
562 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
563 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
564 // Load data |
1674 | 565 if (fread(&memory[loadAddr], dataSize, 1, fh) < 1) |
486 | 566 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
567 res = dmGetErrno(); |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
568 dmPrint(1, " .. Error #%d: %s.\n", |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
569 res, dmErrorStr(res)); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
570 goto out; |
486 | 571 } |
572 | |
573 dmPrint(1, " .. OK\n"); | |
574 | |
575 // Add to list of blocks | |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
576 if (!dmReserveMemBlock(loadAddr, endAddr, filename, MTYPE_RES)) |
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
577 res = DMERR_MALLOC; |
486 | 578 |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
579 out: |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
580 if (fh != NULL) |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
581 fclose(fh); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
582 |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
583 return res; |
486 | 584 } |
585 | |
586 | |
864 | 587 int dmLoadRAW(const char *filename, const int destAddr) |
486 | 588 { |
1674 | 589 FILE *fh; |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
590 int dataSize, endAddr, res = DMERR_OK; |
486 | 591 |
592 // Open the input file | |
1674 | 593 if ((fh = fopen(filename, "rb")) == NULL) |
486 | 594 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
595 res = dmGetErrno(); |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
596 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
|
597 filename, res, dmErrorStr(res)); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
598 goto out; |
486 | 599 } |
600 | |
601 // Get filesize | |
1674 | 602 if ((dataSize = dmGetFileSize(fh)) < 0) |
486 | 603 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
604 res = dmError(DMERR_FREAD, |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
605 "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
|
606 goto out; |
486 | 607 } |
608 | |
609 // Show information | |
610 endAddr = destAddr + dataSize - 1; | |
611 dmPrint(1, "* Loading '%s', RAW at $%.4x-$%.4x", | |
612 filename, destAddr, endAddr); | |
613 | |
614 if (endAddr >= memModel->size) | |
615 { | |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
616 res = DMERR_BOUNDS; |
486 | 617 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
|
618 goto out; |
486 | 619 } |
620 | |
621 // Load data | |
1674 | 622 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
|
623 { |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
624 res = dmGetErrno(); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
625 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
|
626 res, dmErrorStr(res)); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
627 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
|
628 } |
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 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
|
631 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
632 // Add info to list |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
633 if (!dmReserveMemBlock(destAddr, endAddr, filename, MTYPE_RES)) |
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
634 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
|
635 |
1675
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
636 out: |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
637 if (fh != NULL) |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
638 fclose(fh); |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
639 |
bc5a75888fa9
Improve error handling and plug filehandle leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
1674
diff
changeset
|
640 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
|
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 |
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 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
|
645 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
646 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
|
647 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
|
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 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
|
650 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
651 // 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
|
652 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
|
653 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
|
654 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
655 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
|
656 blockName); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
657 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
|
658 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
659 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
660 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
|
661 s = (t + 1); |
1678 | 662 else |
663 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
|
664 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
|
665 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
666 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
|
667 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
668 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
|
669 *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
|
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 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
|
672 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
673 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
|
674 *t = '_'; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
675 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
676 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
677 // 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
|
678 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
|
679 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
680 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
|
681 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
|
682 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
683 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
684 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
|
685 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
|
686 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
687 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
688 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
|
689 default: |
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 - $%.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
|
691 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
|
692 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
|
693 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
694 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
695 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
696 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
|
697 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
|
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 |
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 /* 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
|
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 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
|
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 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
|
706 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
707 |
864 | 708 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
|
709 { |
1678 | 710 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
|
711 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
|
712 } |
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 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
|
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 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
|
717 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
718 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
|
719 |
1678 | 720 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
|
721 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
722 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
|
723 char desc[512], *s; |
864 | 724 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
|
725 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
726 // Check for empty, unreserved areas |
828 | 727 if (prev != NULL) |
728 siz = (curr->start - 1) - (prev->end + 1) + 1; | |
729 else | |
730 siz = 0; | |
1238 | 731 |
499
c9b83226e21a
Fix empty blocks size calculation, was off by one.
Matti Hamalainen <ccr@tnsp.org>
parents:
498
diff
changeset
|
732 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
|
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 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
|
735 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
736 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
|
737 |
500
49701129c5dd
Remove the redundant word 'bytes' from Empty sections in describe output.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
738 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
|
739 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
|
740 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
741 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
|
742 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
|
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 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
|
745 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
746 // 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
|
747 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
|
748 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
749 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
|
750 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
|
751 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
|
752 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
|
753 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
|
754 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
|
755 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
756 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
757 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
|
758 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
|
759 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
760 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
|
761 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
|
762 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
|
763 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
|
764 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
|
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 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
767 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
768 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
|
769 "\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 "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
|
771 "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
|
772 "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
|
773 "\n" |
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 |
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 * 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
|
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 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
|
782 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
783 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
|
784 BOOL hasOverlaps; |
864 | 785 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
|
786 |
1677
c2ad6c0e4975
Bump copyright year and version.
Matti Hamalainen <ccr@tnsp.org>
parents:
1676
diff
changeset
|
787 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
|
788 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
|
789 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
790 // 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
|
791 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
|
792 argHandleOpt, NULL, OPTH_BAILOUT)) |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
793 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
|
794 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
795 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
|
796 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
797 dmErrorMsg("Nothing to do. (try --help)\n"); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
798 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
|
799 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
800 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
801 // 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
|
802 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
|
803 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
|
804 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
|
805 |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
806 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
|
807 { |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
808 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
|
809 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
|
810 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
811 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
812 // 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
|
813 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
|
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 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
|
816 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
817 dmPrint(1, "BYTE 0x%.2x\n", optInitValue); |
1167 | 818 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
|
819 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
820 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
821 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
|
822 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
823 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
|
824 dmPrint(1, "WORD 0x%.4x\n", optInitValue); |
1673 | 825 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
|
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 *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
|
828 } |
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 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
831 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
832 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
|
833 dmPrint(1, "DWORD 0x%.8x\n", optInitValue); |
1673 | 834 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
|
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 *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
|
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 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
839 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
840 // Load the datafiles |
1673 | 841 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
|
842 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
|
843 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
844 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
|
845 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
|
846 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
847 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
848 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
|
849 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
|
850 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
851 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
852 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
|
853 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
|
854 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
855 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
856 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
857 // 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
|
858 dmMsg(1, "Applying memory model restrictions...\n"); |
1673 | 859 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
|
860 { |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
861 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
|
862 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
|
863 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
|
864 memModel->memBlocks[i].name, |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
865 memModel->memBlocks[i].type)) |
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
866 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
|
867 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
868 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
869 // Sort the blocks |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
870 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
|
871 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
872 // 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
|
873 hasOverlaps = FALSE; |
1673 | 874 for (int i = 0; i < nmemBlocks; i++) |
875 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
|
876 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
|
877 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
878 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
|
879 *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
|
880 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
881 // 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
|
882 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
|
883 (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
|
884 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
885 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
|
886 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
|
887 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
|
888 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
|
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 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
891 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
892 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
|
893 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
871
diff
changeset
|
894 dmErrorMsg("Error occured, overlaps not allowed.\n"); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
895 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
|
896 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
897 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
898 // 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
|
899 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
|
900 totalSize = endAddr = 0; |
1673 | 901 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
|
902 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
903 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
|
904 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
|
905 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
906 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
|
907 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
|
908 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
909 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
|
910 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
|
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 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
|
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 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
915 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
916 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
|
917 { |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
918 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
|
919 startAddr, endAddr); |
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
920 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
|
921 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
922 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
923 // 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
|
924 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
|
925 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
926 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
|
927 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
|
928 { |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
929 int err = dmGetErrno(); |
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
930 dmErrorMsg("Error creating file '%s' #%d: %s.\n", |
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
931 optLinkFileName, err, dmErrorStr(err)); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
932 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
933 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
934 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
935 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
|
936 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
937 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
|
938 default: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
939 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
|
940 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
|
941 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
942 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
943 |
1673 | 944 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
|
945 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
946 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
|
947 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
|
948 } |
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 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
|
951 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
952 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
953 // 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
|
954 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
|
955 { |
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
956 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
|
957 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
|
958 } |
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
959 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
960 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
|
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 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
|
963 { |
c1d5cccbf5b3
Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
964 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
|
965 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
|
966 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
967 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
968 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
|
969 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
|
970 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
971 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
972 // 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
|
973 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
|
974 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
975 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
|
976 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
|
977 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
978 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
|
979 { |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
980 int err = dmGetErrno(); |
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
981 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
|
982 optDestName, err, dmErrorStr(err)); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
983 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
|
984 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
985 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
986 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
|
987 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
988 // 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
|
989 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
|
990 { |
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
991 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
|
992 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
|
993 } |
501
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
994 else |
d13d8770477a
Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
995 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
|
996 { |
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
997 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
|
998 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
|
999 } |
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1000 else |
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1001 { |
b0ee847a14d3
Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1002 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
|
1003 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1004 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1005 // 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
|
1006 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
|
1007 { |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
1008 int err = dmGetErrno(); |
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
1009 dmErrorMsg("Error writing to file #%d: %s.\n", |
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1238
diff
changeset
|
1010 err, dmErrorStr(err)); |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1011 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
|
1012 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1013 |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1014 // Describe the memory layout |
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1015 if (optDescribe) |
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1016 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
|
1017 |
1679
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1018 out: |
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1019 if (dfile != NULL && dfile != stdout) |
7b0c76cd7686
Clean up and improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1678
diff
changeset
|
1020 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
|
1021 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1022 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
|
1023 } |