Mercurial > hg > dmlib
comparison objlink.c @ 501:d13d8770477a
Add new -L option for forcing loading address on the destination file, or
disabling it completely (aka "raw" output) via -L none.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 17 Nov 2012 17:04:08 +0200 |
parents | 49701129c5dd |
children | b0ee847a14d3 |
comparison
equal
deleted
inserted
replaced
500:49701129c5dd | 501:d13d8770477a |
---|---|
72 MTYPE_ROM_WT, // Write to RAM through ROM | 72 MTYPE_ROM_WT, // Write to RAM through ROM |
73 MTYPE_IO, // I/O lines | 73 MTYPE_IO, // I/O lines |
74 MTYPE_RES // RESERVED | 74 MTYPE_RES // RESERVED |
75 }; | 75 }; |
76 | 76 |
77 enum | |
78 { | |
79 LA_NONE = -2, | |
80 LA_AUTO = -1 | |
81 }; | |
77 | 82 |
78 /* Memory models | 83 /* Memory models |
79 */ | 84 */ |
80 const DMMemModel memoryModels[] = { | 85 const DMMemModel memoryModels[] = { |
81 { "C64 unrestricted", "$01 = $34", (64*1024), 0, { | 86 { "C64 unrestricted", "$01 = $34", (64*1024), 0, { |
129 | 134 |
130 Uint32 optInitValue = 0; | 135 Uint32 optInitValue = 0; |
131 int optInitValueType = 1; | 136 int optInitValueType = 1; |
132 ssize_t optCropStart, optCropEnd; | 137 ssize_t optCropStart, optCropEnd; |
133 BOOL optCropOutput = FALSE; | 138 BOOL optCropOutput = FALSE; |
139 | |
140 int optLoadAddress = LA_AUTO; | |
134 | 141 |
135 int optMemModel = 0; | 142 int optMemModel = 0; |
136 const DMMemModel *memModel = NULL; | 143 const DMMemModel *memModel = NULL; |
137 Uint8 *memory = NULL; | 144 Uint8 *memory = NULL; |
138 | 145 |
152 { 8, 'l', "link-file", "Output addresses and labels into file", OPT_ARGREQ }, | 159 { 8, 'l', "link-file", "Output addresses and labels into file", OPT_ARGREQ }, |
153 { 9, 'f', "format", "Format of link-file: (g)eneric, (p)lain, (d)ecimal", OPT_ARGREQ }, | 160 { 9, 'f', "format", "Format of link-file: (g)eneric, (p)lain, (d)ecimal", OPT_ARGREQ }, |
154 { 10, 'i', "initvalue", "Initialize memory with: -i <byte/word/dword>:[bwd]", OPT_ARGREQ }, | 161 { 10, 'i', "initvalue", "Initialize memory with: -i <byte/word/dword>:[bwd]", OPT_ARGREQ }, |
155 { 11, 'd', "describe", "Output ASCII memory map description", OPT_NONE }, | 162 { 11, 'd', "describe", "Output ASCII memory map description", OPT_NONE }, |
156 { 13, 'c', "crop", "Crop output file to: -c <start>-<end> or <start>:<len>", OPT_ARGREQ }, | 163 { 13, 'c', "crop", "Crop output file to: -c <start>-<end> or <start>:<len>", OPT_ARGREQ }, |
164 { 14, 'L', "load-address","Set output file load address (or 'none' for 'raw' output)", OPT_ARGREQ }, | |
157 }; | 165 }; |
158 | 166 |
159 static const int optListN = sizeof(optList) / sizeof(optList[0]); | 167 static const int optListN = sizeof(optList) / sizeof(optList[0]); |
160 | 168 |
161 | 169 |
472 | 480 |
473 optCropOutput = TRUE; | 481 optCropOutput = TRUE; |
474 } | 482 } |
475 break; | 483 break; |
476 | 484 |
485 case 14: | |
486 // Set loading address | |
487 if (strcasecmp(optArg, "none") == 0) | |
488 optLoadAddress = LA_NONE; | |
489 else | |
490 { | |
491 optLoadAddress = atoi(optArg); | |
492 if (optLoadAddress < 0 || optLoadAddress >= 64*1024) | |
493 { | |
494 dmError("Invalid or insane loading address %d/$%x!\n", | |
495 optLoadAddress); | |
496 return FALSE; | |
497 } | |
498 } | |
499 break; | |
500 | |
477 default: | 501 default: |
478 dmError("Unknown argument '%s'.\n", currArg); | 502 dmError("Unknown argument '%s'.\n", currArg); |
479 return FALSE; | 503 return FALSE; |
480 } | 504 } |
481 | 505 |
926 } | 950 } |
927 else | 951 else |
928 dmPrint(1, "to '%s'\n", optDestName); | 952 dmPrint(1, "to '%s'\n", optDestName); |
929 | 953 |
930 // Save loading address | 954 // Save loading address |
931 dm_fwrite_le16(dfile, startAddr); | 955 if (optLoadAddress >= 0) |
956 dm_fwrite_le16(dfile, optLoadAddress); | |
957 else | |
958 if (optLoadAddress == LA_AUTO) | |
959 dm_fwrite_le16(dfile, startAddr); | |
932 | 960 |
933 // Save the data | 961 // Save the data |
934 if (fwrite(&memory[startAddr], dataSize, 1, dfile) < 1) | 962 if (fwrite(&memory[startAddr], dataSize, 1, dfile) < 1) |
935 { | 963 { |
936 dmError("Error writing to file (%s)\n", strerror(errno)); | 964 dmError("Error writing to file (%s)\n", strerror(errno)); |