annotate tools/objlink.c @ 1674:0f256e7340a3

Rename varibles.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 31 May 2018 13:03:53 +0300
parents a2b45dddfe79
children bc5a75888fa9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * (C) Copyright 2002-2012 Tecnic Software productions (TNSP)
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #define MAX_FILENAMES (128)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #define MAX_MEMBLOCKS (128)
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
b111cccf45fc Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
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
b111cccf45fc Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
31 int size; // Total addressable memory size
b111cccf45fc Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
32 int nmemBlocks; // Defined memory areas
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 DMMemBlock memBlocks[MAX_MEMBLOCKS];
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
b111cccf45fc Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 DMSourceFile srcFiles[MAX_FILENAMES]; // Source file names
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;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 DMMemBlock memBlocks[MAX_FILENAMES];
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
b111cccf45fc Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
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 int i;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 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
175 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
176
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 printf(
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 "\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 "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
180 "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
181 "\n"
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 "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
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 for (i = 0; i < nmemoryModels; 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 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 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
187 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
188 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
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
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 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
194 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 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
196 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
197 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
198 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
199 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 /* 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
204 */
864
b111cccf45fc Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
205 void reserveMemBlock(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
206 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 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
208 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
209 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
210 blockName, startAddr, endAddr);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 exit(4);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 }
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 if (nmemBlocks < MAX_FILENAMES)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 memBlocks[nmemBlocks].start = startAddr;
497
b02f1bfce53b Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
217 memBlocks[nmemBlocks].end = endAddr;
b02f1bfce53b Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
218 memBlocks[nmemBlocks].name = dm_strdup(blockName);
b02f1bfce53b Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
219 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
220 nmemBlocks++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
224 dmErrorMsg("Maximum number of memBlock definitions (%d) exceeded!\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
225 MAX_FILENAMES);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 exit(4);
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 int compareMemBlock(const void *cva, const void *cvb)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 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
234 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
235 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236
484
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
237
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 864
diff changeset
238 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
239 {
497
b02f1bfce53b Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
240 char sectMode, *sep, *str, *namesep;
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 864
diff changeset
241 unsigned int tmpi;
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");
484
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
248 exit(128);
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);
484
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
256 goto error;
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
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
262 if (!dmGetIntVal(str, sectStart))
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);
484
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
265 goto error;
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
266 }
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
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);
b02f1bfce53b Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
278 goto error;
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);
b02f1bfce53b Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
287 goto error;
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
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
291 if (!dmGetIntVal(sep + 1, &tmpi))
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);
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
296 goto error;
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);
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
309 goto error;
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
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
314 dmFree(str);
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
315 return TRUE;
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
316
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
317 error:
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
318 dmFree(str);
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
319 return FALSE;
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
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
323 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
324 {
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 864
diff changeset
325 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
326 BOOL hasAddr = FALSE;
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
327 char *sep;
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
328
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
329 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
330 {
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
331 *sep = 0;
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
332 if (!dmGetIntVal(sep + 1, &tmpi))
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
333 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
334 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
335 desc, sep + 1, arg);
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
336 return FALSE;
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
337 }
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
338 hasAddr = TRUE;
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
339 }
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
340 else
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
341 if (requireAddr)
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
342 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
343 dmErrorMsg("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
344 return FALSE;
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
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
347 srcFiles[nsrcFiles].filename = arg;
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
348 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
349 srcFiles[nsrcFiles].addr = tmpi;
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
350 nsrcFiles++;
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
351 return TRUE;
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
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
354
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 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
356 {
484
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
357 char *p;
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 864
diff changeset
358 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
359
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360 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
361 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
362 argShowHelp();
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 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
364 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 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
367 // Add RAW
484
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
368 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
369 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
370 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372 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
373 // Add PRG
484
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
374 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
375 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
376 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378 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
379 // 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
380 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
381 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383 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
384 // 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
385 optAllowOverlap = TRUE;
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
386 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
387 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 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
390 // 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
391 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
392 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
393 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
394 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
395 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
396 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 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
400 // 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
401 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
402 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 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
405 // 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
406 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
407 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
408 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
409 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
410 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411 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
412 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
413 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414 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
415 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
416 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
419 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
420 optArg);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 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
422 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425 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
426 // 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
427 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
428 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
429 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 *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
431 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
432 {
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 '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
434 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
435 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
436 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
437 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
438 p[1], optArg);
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
439 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
440 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 if (!dmGetIntVal(optArg, &tmpi))
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
444 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
445 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
446 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447 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
448 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 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
451 // 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
452 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
453 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455 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
456 {
497
b02f1bfce53b Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
457 char *sectName = "Clear";
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 864
diff changeset
458 unsigned int sectStart, sectEnd, sectLen;
497
b02f1bfce53b Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
459 if (!dmParseSection(optArg, &sectStart, &sectEnd, &sectName, 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
460 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
461
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
462 // Allocate memory block
497
b02f1bfce53b Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
463 sectLen = sectEnd - sectStart + 1;
b02f1bfce53b Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
464 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
465 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
466
497
b02f1bfce53b Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
467 reserveMemBlock(sectStart, sectEnd, sectName, MTYPE_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
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
497
b02f1bfce53b Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
477 cropLen = optCropEnd - optCropEnd + 1;
485
c1d5cccbf5b3 Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents: 484
diff changeset
478 dmMsg(1, "Cutting output to $%.4x - $%.4x ($%x, %d bytes)\n",
c1d5cccbf5b3 Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents: 484
diff changeset
479 optCropStart, optCropEnd, cropLen, cropLen);
c1d5cccbf5b3 Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents: 484
diff changeset
480
c1d5cccbf5b3 Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents: 484
diff changeset
481 optCropOutput = TRUE;
c1d5cccbf5b3 Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents: 484
diff changeset
482 }
c1d5cccbf5b3 Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents: 484
diff changeset
483 break;
c1d5cccbf5b3 Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents: 484
diff changeset
484
501
d13d8770477a Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents: 500
diff changeset
485 case 14:
d13d8770477a Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents: 500
diff changeset
486 // Set loading address
d13d8770477a Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents: 500
diff changeset
487 if (strcasecmp(optArg, "none") == 0)
d13d8770477a Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents: 500
diff changeset
488 optLoadAddress = LA_NONE;
d13d8770477a Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents: 500
diff changeset
489 else
d13d8770477a Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents: 500
diff changeset
490 {
504
b0ee847a14d3 Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
491 if (!dmGetIntVal(optArg, &tmpi))
b0ee847a14d3 Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
492 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
493 dmErrorMsg("Invalid loading address '%s'.\n", optArg);
504
b0ee847a14d3 Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
494 return FALSE;
b0ee847a14d3 Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
495 }
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 864
diff changeset
496 if (tmpi >= 64*1024)
501
d13d8770477a Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents: 500
diff changeset
497 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
498 dmErrorMsg("Invalid or insane loading address %d/$%x!\n",
504
b0ee847a14d3 Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
499 tmpi);
501
d13d8770477a Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents: 500
diff changeset
500 return FALSE;
d13d8770477a Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents: 500
diff changeset
501 }
504
b0ee847a14d3 Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
502 optLoadAddress = tmpi;
501
d13d8770477a Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents: 500
diff changeset
503 }
d13d8770477a Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents: 500
diff changeset
504 break;
d13d8770477a Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents: 500
diff changeset
505
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
507 dmErrorMsg("Unknown argument '%s'.\n", currArg);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508 return FALSE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 return TRUE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
512 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
514
864
b111cccf45fc Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
515 int dmLoadPRG(const char *filename, BOOL forceAddr, const int destAddr)
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516 {
864
b111cccf45fc Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
517 int dataSize, loadAddr, endAddr;
1674
0f256e7340a3 Rename varibles.
Matti Hamalainen <ccr@tnsp.org>
parents: 1673
diff changeset
518 FILE *fh;
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
519 Uint16 tmpAddr;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
520
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
521 // Open the input file
1674
0f256e7340a3 Rename varibles.
Matti Hamalainen <ccr@tnsp.org>
parents: 1673
diff changeset
522 if ((fh = fopen(filename, "rb")) == NULL)
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
523 {
1431
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
524 int err = dmGetErrno();
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
525 dmErrorMsg("Error opening input file '%s' #%d: %s.\n",
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
526 filename, err, dmErrorStr(err));
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
527 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
528 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530 // Get filesize
1674
0f256e7340a3 Rename varibles.
Matti Hamalainen <ccr@tnsp.org>
parents: 1673
diff changeset
531 if ((dataSize = dmGetFileSize(fh) - 2) < 0)
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
532 {
1431
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
533 int err = dmGetErrno();
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
534 dmErrorMsg("Error getting file size for '%s' #%d: %s.\n",
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
535 filename, err, dmErrorStr(err));
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
536 return 6;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
537 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
538
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539 // Get loading address
1674
0f256e7340a3 Rename varibles.
Matti Hamalainen <ccr@tnsp.org>
parents: 1673
diff changeset
540 if (!dm_fread_le16(fh, &tmpAddr))
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
541 {
1431
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
542 int err = dmGetErrno();
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
543 dmErrorMsg("Error reading input file '%s' #%d: %s.\n",
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
544 filename, err, dmErrorStr(err));
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
545 return 2;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
546 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
547
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
548 // Show information
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
549 loadAddr = forceAddr ? destAddr : tmpAddr;
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
550 endAddr = loadAddr + dataSize - 1;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
551
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
552 dmPrint(1, "* Loading '%s', %s at $%.4x-$%.4x",
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
553 filename, forceAddr ? "PRGA" : "PRG", loadAddr, endAddr);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
554
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
555 if (endAddr >= memModel->size)
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
556 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
557 dmPrint(1, " .. Does not fit into the memory!\n");
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
558 return 5;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
559 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
560
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
561 // Load data
1674
0f256e7340a3 Rename varibles.
Matti Hamalainen <ccr@tnsp.org>
parents: 1673
diff changeset
562 if (fread(&memory[loadAddr], dataSize, 1, fh) < 1)
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
563 {
1431
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
564 int err = dmGetErrno();
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
565 dmPrint(1, " .. Error #%d: %s.\n",
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
566 err, dmErrorStr(err));
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
567 return 4;
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
568 }
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
569
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
570 dmPrint(1, " .. OK\n");
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
571
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
572 // Add to list of blocks
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
573 reserveMemBlock(loadAddr, endAddr, filename, MTYPE_RES);
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
574
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
575 return 0;
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
576 }
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
577
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
578
864
b111cccf45fc Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
579 int dmLoadRAW(const char *filename, const int destAddr)
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
580 {
864
b111cccf45fc Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
581 int dataSize, endAddr;
1674
0f256e7340a3 Rename varibles.
Matti Hamalainen <ccr@tnsp.org>
parents: 1673
diff changeset
582 FILE *fh;
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
583
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
584 // Open the input file
1674
0f256e7340a3 Rename varibles.
Matti Hamalainen <ccr@tnsp.org>
parents: 1673
diff changeset
585 if ((fh = fopen(filename, "rb")) == NULL)
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
586 {
1431
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
587 int err = dmGetErrno();
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
588 dmErrorMsg("Error opening input file '%s' #%d: %s.\n",
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
589 filename, err, dmErrorStr(err));
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
590 return 1;
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
591 }
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
592
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
593 // Get filesize
1674
0f256e7340a3 Rename varibles.
Matti Hamalainen <ccr@tnsp.org>
parents: 1673
diff changeset
594 if ((dataSize = dmGetFileSize(fh)) < 0)
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
595 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
596 dmErrorMsg("Error getting file size for '%s'.\n", filename);
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
597 return 6;
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
598 }
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
599
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
600 // Show information
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
601 endAddr = destAddr + dataSize - 1;
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
602 dmPrint(1, "* Loading '%s', RAW at $%.4x-$%.4x",
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
603 filename, destAddr, endAddr);
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
604
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
605 if (endAddr >= memModel->size)
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
606 {
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
607 dmPrint(1, " .. Does not fit into the memory!\n");
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
608 return 5;
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
609 }
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
610
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
611 // Load data
1674
0f256e7340a3 Rename varibles.
Matti Hamalainen <ccr@tnsp.org>
parents: 1673
diff changeset
612 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
613 {
1431
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
614 int err = dmGetErrno();
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
615 dmPrint(1, " .. Error #%d: %s.\n",
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
616 err, dmErrorStr(err));
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
617 return 4;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
618 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
619
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
620 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
621
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
622 // Add info to list
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
623 reserveMemBlock(destAddr, endAddr, filename, MTYPE_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
624
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
625 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
626 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
627
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
628
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
629 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
630 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
631 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
632 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
633
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
634 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
635
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
636 // 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
637 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
638 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
639 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
640 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
641 blockName);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
642 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
645 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
646 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
647 else 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
648 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
649 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
650 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
651
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
652 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
653 *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
654
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
655 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
656 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
657 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
658 *t = '_';
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
661 // 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
662 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
663 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
664 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
665 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
666 break;
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 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
669 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
670 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
671
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
672 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
673 default:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
674 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
675 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
676 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
677 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
678 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
679
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
680 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
681 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
682 }
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
685 /* 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
686 */
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
687 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
688 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
689 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
690 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
691
864
b111cccf45fc Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
692 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
693 {
864
b111cccf45fc Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
694 int 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
695 for (i = 0; i < n; i++)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
696 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
697 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
698
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
699 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
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 int i;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
702 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
703
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
704 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
705
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
706 for (i = 0; i < nmemBlocks; i++)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
707 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
708 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
709 char desc[512], *s;
864
b111cccf45fc Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
710 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
711
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
712 // Check for empty, unreserved areas
828
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
713 if (prev != NULL)
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
714 siz = (curr->start - 1) - (prev->end + 1) + 1;
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
715 else
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
716 siz = 0;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
717
499
c9b83226e21a Fix empty blocks size calculation, was off by one.
Matti Hamalainen <ccr@tnsp.org>
parents: 498
diff changeset
718 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
719 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
720 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
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 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
723
500
49701129c5dd Remove the redundant word 'bytes' from Empty sections in describe output.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
724 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
725 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
726
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
727 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
728 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
729 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
730 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
731
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
732 // 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
733 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
734 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
735 case 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
736 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
737 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
738 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
739 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
740 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
741 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
742
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
743 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
744 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
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 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
747 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
748 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
749 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
750 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
751
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
752 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
753
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
754 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
755 "\n"
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
756 "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
757 "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
758 "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
759 "\n"
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
760 );
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
761 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
762
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
763
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
764 /*
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
765 * 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
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 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
768 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
769 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
770 BOOL hasOverlaps;
864
b111cccf45fc Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
771 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
772
830
7171aa63edb0 Bump objlink version.
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
773 dmInitProg("objlink", "Simple file-linker", "0.81", 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
774 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
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 // 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
777 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
778 argHandleOpt, NULL, OPTH_BAILOUT))
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
779 exit(1);
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 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
782 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
783 dmErrorMsg("Nothing to do. (try --help)\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
784 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
785 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
786
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
787 // 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
788 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
789 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
790 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
791
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
792 memory = (Uint8 *) dmMalloc(memModel->size + 32);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
793 if (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
794 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
795 dmErrorMsg("Could not allocate memory.\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
796 exit(2);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
797 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
798
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
799 // 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
800 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
801
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
802 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
803 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
804 dmPrint(1, "BYTE 0x%.2x\n", optInitValue);
1167
848a88ce7a57 Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
805 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
806 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
807 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
808 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
809 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
810 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
811 dmPrint(1, "WORD 0x%.4x\n", optInitValue);
1673
a2b45dddfe79 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
812 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
813 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
814 *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
815 }
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 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
818 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
819 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
820 dmPrint(1, "DWORD 0x%.8x\n", optInitValue);
1673
a2b45dddfe79 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
821 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
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 *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
824 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
825 }
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 // Load the datafiles
1673
a2b45dddfe79 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
828 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
829 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
830 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
831 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
832 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
833 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
834
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
835 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
836 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
837 break;
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 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
840 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
841 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
842 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
843
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
844 // 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
845 dmMsg(1, "Applying memory model restrictions...\n");
1673
a2b45dddfe79 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
846 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
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 reserveMemBlock(
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
849 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
850 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
851 memModel->memBlocks[i].name,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
852 memModel->memBlocks[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
853 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
854
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
855 // Sort the blocks
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
856 qsort(memBlocks, nmemBlocks, sizeof(DMMemBlock), compareMemBlock);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
857
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
858 // 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
859 hasOverlaps = FALSE;
1673
a2b45dddfe79 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
860 for (int i = 0; i < nmemBlocks; i++)
a2b45dddfe79 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
861 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
862 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
863 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
864 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
865 *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
866
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
867 // 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
868 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
869 (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
870 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
871 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
872 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
873 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
874 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
875 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
876 }
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 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
879 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
880 dmErrorMsg("Error occured, overlaps not allowed.\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
881 exit(5);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
882 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
883
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
884 // 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
885 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
886 totalSize = endAddr = 0;
1673
a2b45dddfe79 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
887 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
888 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
889 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
890 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
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 (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
893 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
894
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
895 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
896 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
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 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
899 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
900 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
901
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
902 if (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
903 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
904 dmErrorMsg("Invalid saveblock addresses (start=$%.4x, end=$%.4x)!\n", startAddr, 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
905 exit(8);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
906 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
907
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
908 // 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
909 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
910 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
911 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
912 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
913 {
1431
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
914 int err = dmGetErrno();
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
915 dmErrorMsg("Error creating file '%s' #%d: %s.\n",
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
916 optLinkFileName, err, dmErrorStr(err));
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
917 exit(1);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
918 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
919
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
920 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
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 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
923 default:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
924 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
925 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
926 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
927 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
928
1673
a2b45dddfe79 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
929 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
930 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
931 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
932 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
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 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
938 // 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
939 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
940 {
c1d5cccbf5b3 Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents: 484
diff changeset
941 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
942 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
943 }
c1d5cccbf5b3 Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents: 484
diff changeset
944
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 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
946
c1d5cccbf5b3 Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents: 484
diff changeset
947 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
948 {
c1d5cccbf5b3 Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents: 484
diff changeset
949 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
950 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
951 }
407
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 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
954 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
955
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
956
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
957 // 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
958 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
959 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
960 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
961 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
962 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
963 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
964 {
1431
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
965 int err = dmGetErrno();
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
966 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
967 optDestName, err, dmErrorStr(err));
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
968 exit(1);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
969 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
970 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
971 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
972
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
973 // 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
974 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
975 {
b0ee847a14d3 Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
976 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
977 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
978 }
501
d13d8770477a Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents: 500
diff changeset
979 else
d13d8770477a Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents: 500
diff changeset
980 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
981 {
b0ee847a14d3 Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
982 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
983 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
984 }
b0ee847a14d3 Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
985 else
b0ee847a14d3 Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
986 {
b0ee847a14d3 Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
987 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
988 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
989
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
990 // 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
991 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
992 {
1431
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
993 int err = dmGetErrno();
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
994 dmErrorMsg("Error writing to file #%d: %s.\n",
ed04fb6da07c Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
995 err, dmErrorStr(err));
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
996 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
997
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
998 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
999
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1000 // Describe
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1001 if (optDescribe)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1002 dmDescribeMemory(stdout);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1003
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1004 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
1005 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
1006 }