changeset 485:c1d5cccbf5b3

Implement output data cropping option -c, with which the memory area to be stored in output can be specified. For example -c 0x1000-0x2000.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 11 Nov 2012 13:05:51 +0200
parents 81b92a0e754b
children cb61c44f7846
files objlink.c
diffstat 1 files changed, 28 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/objlink.c	Sun Nov 11 13:05:04 2012 +0200
+++ b/objlink.c	Sun Nov 11 13:05:51 2012 +0200
@@ -130,6 +130,8 @@
 
 Uint32     optInitValue = 0;
 int        optInitValueType = 1;
+ssize_t    optCropStart, optCropEnd;
+BOOL       optCropOutput = FALSE;
 
 int        optMemModel = 0;
 const DMMemModel *memModel = NULL;
@@ -152,6 +154,7 @@
     {  9, 'f', "format",      "Format of link-file: (g)eneric, (p)lain, (d)ecimal", OPT_ARGREQ },
     { 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 },
 };
 
 static const int optListN = sizeof(optList) / sizeof(optList[0]);
@@ -437,6 +440,19 @@
         }
         break;
 
+    case 13:
+        {
+            ssize_t cropLen;
+            if (!dmParseSection(optArg, &optCropStart, &optCropEnd, &cropLen))
+                return FALSE;
+
+            dmMsg(1, "Cutting output to $%.4x - $%.4x ($%x, %d bytes)\n",
+                optCropStart, optCropEnd, cropLen, cropLen);
+
+            optCropOutput = TRUE;
+        }
+        break;
+
     default:
         dmError("Unknown argument '%s'.\n", currArg);
         return FALSE;
@@ -866,9 +882,19 @@
     }
 
     // Show some information
+    if (optCropOutput)
+    {
+        startAddr = optCropStart;
+        endAddr = optCropEnd;
+    }
+
     dataSize = endAddr - startAddr + 1;
-    dmMsg(1, "Total of %d/$%x bytes unused(?) areas.\n",
-        dataSize - totalSize, dataSize - totalSize);
+
+    if (dataSize - totalSize > 0)
+    {
+        dmMsg(1, "Total of %d/$%x bytes unused(?) areas.\n",
+            dataSize - totalSize, dataSize - totalSize);
+    }
 
     dmMsg(1, "Writing $%.4x - $%.4x (%d/$%x bytes) ",
         startAddr, endAddr, dataSize, dataSize);