annotate tools/objlink.c @ 830:7171aa63edb0

Bump objlink version.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 17 May 2014 23:28:53 +0300
parents c20a99411a1a
children daebbf28953d
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 */
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include <errno.h>
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 #include "dmmutex.h"
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
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_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
15 #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
16
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 /* Typedefs
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 */
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 typedef struct
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 ssize_t start, end; // Start and end address
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 int type; // Type
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 char *name; // Name of the block
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 int placement;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 } DMMemBlock;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 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
29 {
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 *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
31 char *desc;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 ssize_t size; // Total addressable memory size
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 ssize_t nmemBlocks; // Defined memory areas
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 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
35 } DMMemModel;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 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
38 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 char *filename;
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 type;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 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
42 ssize_t addr;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 } DMSourceFile;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 // 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
46 enum
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 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
49 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
50 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 // 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
54 enum
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 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
57 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
58 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 enum
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 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
64 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
65 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 enum
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 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
71 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
72 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
73 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
74 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
75 };
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76
501
d13d8770477a Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents: 500
diff changeset
77 enum
d13d8770477a Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents: 500
diff changeset
78 {
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_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
80 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
81 };
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 /* 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
84 */
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 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
86 { "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
87 { 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 { "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
91 { 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
92 { 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
93 { 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 { "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
97 { 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
98 { 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 { "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
102 { 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 { "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
106 { 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
107 { 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
108 { 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
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 /*
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 { "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
113 { 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 /* 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
122 */
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 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
124 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
125
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 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
127 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
128
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 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
130 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
131
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 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
133 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
134
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 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
136 int optInitValueType = 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
137 ssize_t optCropStart, optCropEnd;
c1d5cccbf5b3 Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents: 484
diff changeset
138 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
139
504
b0ee847a14d3 Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
140 ssize_t 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
141
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 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
143 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
144 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
145
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 /* Arguments
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 */
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 static DMOptArg optList[] = {
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]");
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 dmArgsPrintHelp(stdout, optList, optListN);
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 */
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 void reserveMemBlock(ssize_t startAddr, ssize_t endAddr, const char *blockName, int blockType)
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 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 dmError("ERROR! Block '%s' has startAddr=$%.4x > endAddr=$%.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
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 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 dmError("Maximum number of memBlock definitions (%d) exceeded!\n",
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
497
b02f1bfce53b Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
238 BOOL dmParseSection(const char *arg, ssize_t *sectStart, ssize_t *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;
484
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
241 ssize_t tmpi;
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 {
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
247 dmError("Could not allocate temporary string!\n");
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 {
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
255 dmError("Section definition '%s' invalid.\n", arg);
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 {
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
264 dmError("Section start address '%s' in '%s' invalid.\n", str, arg);
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 }
497
b02f1bfce53b Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
267
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 {
b02f1bfce53b Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
276 dmError("Section definition '%s' name is empty. Either specify name or leave it out.\n",
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 {
b02f1bfce53b Improve and clean up section parsing support.
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
285 dmError("Section definition does not allow a name, syntax error in '%s' at '%s'.\n",
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 {
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
293 dmError("Section %s '%s' in '%s' invalid.\n",
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 {
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
307 dmError("Section start address > end address in '%s'.\n",
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 {
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
325 ssize_t tmpi = 0;
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 {
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
334 dmError("Invalid %s address '%s' specified for '%s'.\n",
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 {
81b92a0e754b Clean up and modularize parsing of some options (specifying sections).
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
343 dmError("No %s loading address specified for '%s'.\n", desc, arg);
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;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 ssize_t tmpi;
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;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 dmError("Warning, allowing overlapping data.\n");
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 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 dmError("Invalid memory model number %i!\n", optMemModel);
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:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 dmError("Invalid/unknown linker file format '%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
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:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437 dmError("Invalid init value type '%c' specified for '%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
438 p[1], optArg);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 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
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 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444 dmError("Invalid initvalue '%s'.\n", optArg);
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";
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458 ssize_t 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 {
b0ee847a14d3 Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
493 dmError("Invalid loading address '%s'.\n", optArg);
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 }
b0ee847a14d3 Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
496 if (tmpi < 0 || 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 {
d13d8770477a Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents: 500
diff changeset
498 dmError("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:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
507 dmError("Unknown argument '%s'.\n", currArg);
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
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
515 int dmLoadPRG(const char *filename, BOOL forceAddr, const ssize_t 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 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
517 FILE *f;
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
518 ssize_t dataSize, loadAddr, endAddr;
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
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
522 if ((f = 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 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
524 dmError("Error opening input file '%s' (%s).\n",
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
525 filename, strerror(errno));
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
526 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
527 }
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 // Get filesize
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
530 if ((dataSize = dmGetFileSize(f) - 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
531 {
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
532 dmError("Error getting file size for '%s'.\n", filename);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
533 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
534 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
535
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
536 // Get loading address
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
537 if (!dm_fread_le16(f, &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
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 dmError("Error reading input file '%s' (%s).\n",
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
540 filename, strerror(errno));
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 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
542 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
543
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
544 // Show information
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
545 loadAddr = forceAddr ? destAddr : tmpAddr;
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
546 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
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 dmPrint(1, "* Loading '%s', %s at $%.4x-$%.4x",
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
549 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
550
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
551 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
552 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
553 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
554 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
555 }
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 // Load data
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
558 if (fread(&memory[loadAddr], dataSize, 1, f) < 1)
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
559 {
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
560 dmPrint(1, " .. Error: %s.\n",
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
561 strerror(errno));
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
562 return 4;
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
563 }
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
564
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
565 dmPrint(1, " .. OK\n");
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
566
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
567 // Add to list of blocks
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
568 reserveMemBlock(loadAddr, endAddr, filename, MTYPE_RES);
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 return 0;
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
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
573
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
574 int dmLoadRAW(const char *filename, const ssize_t destAddr)
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
575 {
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
576 FILE *f;
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
577 ssize_t dataSize, endAddr;
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
578
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
579 // Open the input file
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
580 if ((f = fopen(filename, "rb")) == NULL)
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
581 {
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
582 dmError("Error opening input file '%s' (%s).\n",
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
583 filename, strerror(errno));
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
584 return 1;
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
585 }
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
586
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
587 // Get filesize
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
588 if ((dataSize = dmGetFileSize(f)) < 0)
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
589 {
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
590 dmError("Error getting file size for '%s'.\n", filename);
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
591 return 6;
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
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
594 // Show information
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
595 endAddr = destAddr + dataSize - 1;
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
596 dmPrint(1, "* Loading '%s', RAW at $%.4x-$%.4x",
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
597 filename, destAddr, endAddr);
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 if (endAddr >= memModel->size)
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
600 {
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
601 dmPrint(1, " .. Does not fit into the memory!\n");
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
602 return 5;
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
603 }
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 // Load data
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
606 if (fread(&memory[destAddr], dataSize, 1, f) < 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
607 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
608 dmPrint(1, " .. Error: %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
609 strerror(errno));
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
610 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
611 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
612
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
613 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
614
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
615 // Add info to list
486
cb61c44f7846 Clean up PRG/RAW loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
616 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
617
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
618 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
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
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 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
623 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
624 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
625 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
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 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
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 // 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
630 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
631 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
632 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
633 dmError("Could not allocate memory for string '%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
634 blockName);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
635 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
636 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
637
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 ((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
639 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
640 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
641 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
642 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
643 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
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(s, '.')))
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
646 *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
647
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
648 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
649 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
650 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
651 *t = '_';
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
652 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
653
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
654 // 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
655 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
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 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
658 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
659 break;
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 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
662 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
663 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
664
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
665 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
666 default:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
667 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
668 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
669 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
673 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
674 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
675 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
676
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
677
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
678 /* 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
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 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
681 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
682 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
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 void memPrintEmpty(FILE *f, ssize_t n)
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 ssize_t i;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
688 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
692 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
693 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
694 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
695 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
696
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
697 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
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 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
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 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
702 char desc[512], *s;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
703 ssize_t siz, kz;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
704
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
705 // Check for empty, unreserved areas
828
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
706 if (prev != NULL)
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
707 siz = (curr->start - 1) - (prev->end + 1) + 1;
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
708 else
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
709 siz = 0;
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
710
499
c9b83226e21a Fix empty blocks size calculation, was off by one.
Matti Hamalainen <ccr@tnsp.org>
parents: 498
diff changeset
711 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
712 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
713 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
714
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
715 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
716
500
49701129c5dd Remove the redundant word 'bytes' from Empty sections in describe output.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
717 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
718 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
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 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
721 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
722 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
723 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
724
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
725 // 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
726 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
727 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
728 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
729 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
730 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
731 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
732 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
733 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
736 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
737 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
738
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
739 if (kz > 1) memPrintEmpty(f, kz);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
740 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
741 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
742 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
743 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
744
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
745 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
746
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
747 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
748 "\n"
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
749 "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
750 "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
751 "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
752 "\n"
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
753 );
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
754 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
755
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
756
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
757 /*
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
758 * 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
759 */
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
760 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
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 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
763 BOOL hasOverlaps;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
764 int i, j;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
765 ssize_t startAddr, endAddr, dataSize, totalSize;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
766
830
7171aa63edb0 Bump objlink version.
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
767 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
768 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
769
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
770 // 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
771 if (!dmArgsProcess(argc, argv, optList, optListN,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
772 argHandleOpt, NULL, TRUE))
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
773 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
774
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
775 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
776 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
777 dmError("Nothing to do. (try --help)\n");
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
778 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
779 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
780
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
781 // 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
782 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
783 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
784 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
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 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
787 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
788 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
789 dmError("Could not allocate 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
790 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
791 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
792
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
793 // 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
794 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
795
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
796 if (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
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 dmPrint(1, "BYTE 0x%.2x\n", optInitValue);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
799 memset(memory, optInitValue, 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
800 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
801 else
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 == 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
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 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
805 dmPrint(1, "WORD 0x%.4x\n", optInitValue);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
806 for (i = memModel->size / sizeof(*mp); i; i--)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
807 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
808 *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
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 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
811 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
812 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
813 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
814 dmPrint(1, "DWORD 0x%.8x\n", 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 for (i = memModel->size / sizeof(*mp); i; i--)
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 *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
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 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
820
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
821 // Load the datafiles
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
822 for (i = 0; i < nsrcFiles; i++)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
823 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
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 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
826 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
827 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
828
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
829 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
830 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
831 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
832
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
833 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
834 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
835 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
836 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
837
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
838 // 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
839 dmMsg(1, "Applying memory model restrictions...\n");
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
840 for (i = 0; i < memModel->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
841 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
842 reserveMemBlock(
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
843 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
844 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
845 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
846 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
849 // 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
850 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
851
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
852 // 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
853 hasOverlaps = FALSE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
854 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
855 for (j = 0; j < nmemBlocks; j++)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
856 if (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
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 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
859 *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
860
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
861 // 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
862 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
863 (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
864 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
865 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
866 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
867 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
868 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
869 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
870 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
871
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
872 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
873 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
874 dmError("Error occured, overlaps not allowed.\n");
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
875 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
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 // 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
879 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
880 totalSize = endAddr = 0;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
881 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
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 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
884 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
885 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
886 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
887 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
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 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
890 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
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 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
893 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
894 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
895
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
896 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
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 dmError("Invalid saveblock addresses (start=$%.4x, end=$%.4x)!\n", 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
899 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
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 // 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
903 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
904 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
905 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
906 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
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 dmError("Error creating file '%s' (%s).\n", optLinkFileName, strerror(errno));
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
909 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
912 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
913 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
914 case 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
915 default:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
916 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
917 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
918 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
919 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
920
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
921 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
922 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
923 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
924 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
925 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
926
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
927 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
928 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
929
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
930 // 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
931 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
932 {
c1d5cccbf5b3 Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents: 484
diff changeset
933 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
934 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
935 }
c1d5cccbf5b3 Implement output data cropping option -c, with which the memory area to be
Matti Hamalainen <ccr@tnsp.org>
parents: 484
diff changeset
936
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
937 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
938
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 (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
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 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
942 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
943 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
944
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
945 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
946 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
947
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
948
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
949 // 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
950 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
951 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
952 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
953 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
954 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
955 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
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 dmError("Error creating output file '%s' (%s).\n", optDestName, strerror(errno));
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
958 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
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 else
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, "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
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 // 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
964 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
965 {
b0ee847a14d3 Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
966 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
967 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
968 }
501
d13d8770477a Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents: 500
diff changeset
969 else
d13d8770477a Add new -L option for forcing loading address on the destination file, or
Matti Hamalainen <ccr@tnsp.org>
parents: 500
diff changeset
970 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
971 {
b0ee847a14d3 Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
972 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
973 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
974 }
b0ee847a14d3 Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
975 else
b0ee847a14d3 Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
976 {
b0ee847a14d3 Oops, actually fix the load address setting functionality to work. And make
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
977 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
978 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
979
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
980 // 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
981 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
982 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
983 dmError("Error writing to file (%s)\n", strerror(errno));
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
984 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
985
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
986 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
987
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
988 // Describe
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
989 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
990 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
991
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
992 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
993 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
994 }