changeset 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 e1526854e735
files objlink.c
diffstat 1 files changed, 29 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/objlink.c	Sat Nov 17 15:32:42 2012 +0200
+++ b/objlink.c	Sat Nov 17 17:04:08 2012 +0200
@@ -74,6 +74,11 @@
     MTYPE_RES         // RESERVED
 };
 
+enum
+{
+    LA_NONE = -2,
+    LA_AUTO = -1
+};
 
 /* Memory models
  */
@@ -132,6 +137,8 @@
 ssize_t    optCropStart, optCropEnd;
 BOOL       optCropOutput = FALSE;
 
+int        optLoadAddress = LA_AUTO;
+
 int        optMemModel = 0;
 const DMMemModel *memModel = NULL;
 Uint8      *memory = NULL;
@@ -154,6 +161,7 @@
     { 10, 'i', "initvalue",   "Initialize memory with: -i <byte/word/dword>:[bwd]", OPT_ARGREQ },
     { 11, 'd', "describe",    "Output ASCII memory map description", OPT_NONE },
     { 13, 'c', "crop",        "Crop output file to: -c <start>-<end> or <start>:<len>", OPT_ARGREQ },
+    { 14, 'L', "load-address","Set output file load address (or 'none' for 'raw' output)", OPT_ARGREQ },
 };
 
 static const int optListN = sizeof(optList) / sizeof(optList[0]);
@@ -474,6 +482,22 @@
         }
         break;
 
+    case 14:
+        // Set loading address
+        if (strcasecmp(optArg, "none") == 0)
+            optLoadAddress = LA_NONE;
+        else
+        {
+            optLoadAddress = atoi(optArg);
+            if (optLoadAddress < 0 || optLoadAddress >= 64*1024)
+            {
+                dmError("Invalid or insane loading address %d/$%x!\n",
+                    optLoadAddress);
+                return FALSE;
+            }
+        }
+        break;
+
     default:
         dmError("Unknown argument '%s'.\n", currArg);
         return FALSE;
@@ -928,7 +952,11 @@
         dmPrint(1, "to '%s'\n", optDestName);
 
     // Save loading address
-    dm_fwrite_le16(dfile, startAddr);
+    if (optLoadAddress >= 0)
+        dm_fwrite_le16(dfile, optLoadAddress);
+    else
+    if (optLoadAddress == LA_AUTO)
+        dm_fwrite_le16(dfile, startAddr);
 
     // Save the data
     if (fwrite(&memory[startAddr], dataSize, 1, dfile) < 1)