]> git.sur5r.net Git - cc65/blobdiff - src/da65/main.c
Added capability to conver o65 object files by using the new co65 utility
[cc65] / src / da65 / main.c
index c2d4ed563254507c9c57de0cc71d200cf198bd69..fcb1ccfceea954e6a8e412b94ab0abdacc20e20e 100644 (file)
@@ -43,6 +43,7 @@
 #include "abend.h"
 #include "cmdline.h"
 #include "fname.h"
+#include "print.h"
 #include "version.h"
 
 /* da65 */
@@ -60,7 +61,7 @@
 
 
 /*****************************************************************************/
-/*                                          Code                                    */
+/*                                          Code                                    */
 /*****************************************************************************/
 
 
@@ -76,20 +77,49 @@ static void Usage (void)
                     "  -o name\t\tName the output file\n"
                     "  -v\t\t\tIncrease verbosity\n"
                     "  -F\t\t\tAdd formfeeds to the output\n"
-                    "  -V\t\t\tPrint the assembler version\n"
+            "  -S addr\t\tSet the start/load address\n"
+                    "  -V\t\t\tPrint the disassembler version\n"
             "\n"
             "Long options:\n"
                     "  --cpu type\t\tSet cpu type\n"
             "  --formfeeds\t\tAdd formfeeds to the output\n"
             "  --help\t\tHelp (this text)\n"
                     "  --pagelength n\tSet the page length for the listing\n"
+                    "  --start-addr addr\tSet the start/load address\n"
                     "  --verbose\t\tIncrease verbosity\n"
-                    "  --version\t\tPrint the assembler version\n",
+                    "  --version\t\tPrint the disassembler version\n",
             ProgName);
 }
 
 
 
+static unsigned long CvtNumber (const char* Arg, const char* Number)
+/* Convert a number from a string. Allow '$' and '0x' prefixes for hex
+ * numbers.
+ */
+{
+    unsigned long Val;
+    int          Converted;
+
+    /* Convert */
+    if (*Number == '$') {
+       ++Number;
+       Converted = sscanf (Number, "%lx", &Val);
+    } else {
+       Converted = sscanf (Number, "%li", (long*)&Val);
+    }
+
+    /* Check if we do really have a number */
+    if (Converted != 1) {
+               Error ("Invalid number given in argument: %s\n", Arg);
+    }
+
+    /* Return the result */
+    return Val;
+}
+
+
+
 static void OptCPU (const char* Opt, const char* Arg)
 /* Handle the --cpu option */
 {
@@ -113,7 +143,8 @@ static void OptCPU (const char* Opt, const char* Arg)
 
 
 
-static void OptFormFeeds (const char* Opt, const char* Arg)
+static void OptFormFeeds (const char* Opt attribute ((unused)),
+                         const char* Arg attribute ((unused)))
 /* Add form feeds to the output */
 {
     FormFeeds = 1;
@@ -121,7 +152,8 @@ static void OptFormFeeds (const char* Opt, const char* Arg)
 
 
 
-static void OptHelp (const char* Opt, const char* Arg)
+static void OptHelp (const char* Opt attribute ((unused)),
+                    const char* Arg attribute ((unused)))
 /* Print usage information and exit */
 {
     Usage ();
@@ -130,15 +162,11 @@ static void OptHelp (const char* Opt, const char* Arg)
 
 
 
-static void OptPageLength (const char* Opt, const char* Arg)
+static void OptPageLength (const char* Opt attribute ((unused)), const char* Arg)
 /* Handle the --pagelength option */
 {
-    int Len;
-    if (Arg == 0) {
-       NeedArg (Opt);
-    }
-    Len = atoi (Arg);
-    if (Len != -1 && (Len < MIN_PAGE_LEN || Len > MAX_PAGE_LEN)) {
+    int Len = atoi (Arg);
+    if (Len != 0 && (Len < MIN_PAGE_LEN || Len > MAX_PAGE_LEN)) {
        AbEnd ("Invalid page length: %d", Len);
     }
     PageLength = Len;
@@ -146,7 +174,16 @@ static void OptPageLength (const char* Opt, const char* Arg)
 
 
 
-static void OptVerbose (const char* Opt, const char* Arg)
+static void OptStartAddr (const char* Opt, const char* Arg)
+/* Set the default start address */
+{
+    StartAddr = CvtNumber (Opt, Arg);
+}
+
+
+
+static void OptVerbose (const char* Opt attribute ((unused)),
+                       const char* Arg attribute ((unused)))
 /* Increase verbosity */
 {
     ++Verbosity;
@@ -154,7 +191,8 @@ static void OptVerbose (const char* Opt, const char* Arg)
 
 
 
-static void OptVersion (const char* Opt, const char* Arg)
+static void OptVersion (const char* Opt attribute ((unused)),
+                       const char* Arg attribute ((unused)))
 /* Print the disassembler version */
 {
     fprintf (stderr,
@@ -174,9 +212,8 @@ static void OneOpcode (unsigned RemainingBytes)
     const OpcDesc* D = &OpcTable[OPC];
 
     /* If we have a label at this address, output the label */
-    const char* Label = GetLabel (PC);
-    if (Label) {
-       DefLabel (Label);
+    if (MustDefLabel (PC)) {
+       DefLabel (GetLabel (PC));
     }
 
     /* Check...
@@ -185,7 +222,7 @@ static void OneOpcode (unsigned RemainingBytes)
      *   - ...if there is no label somewhere between the instruction bytes.
      * If any of these conditions is true, switch to data mode.
      */
-    if (GetStyle (PC) == atDefault) {
+    if (GetStyleAttr (PC) == atDefault) {
        if (D->Size > RemainingBytes) {
            MarkAddr (PC, atIllegal);
                } else if ((D->CPU & CPU) != CPU) {
@@ -202,7 +239,7 @@ static void OneOpcode (unsigned RemainingBytes)
     }
 
     /* Disassemble the line */
-    switch (GetStyle (PC)) {
+    switch (GetStyleAttr (PC)) {
 
        case atDefault:
        case atCode:
@@ -211,15 +248,27 @@ static void OneOpcode (unsigned RemainingBytes)
            break;
 
        case atByteTab:
-           ByteTable (RemainingBytes);
+           ByteTable ();
            break;
 
        case atWordTab:
-           WordTable (RemainingBytes);
+           WordTable ();
            break;
 
+       case atDWordTab:
+           DWordTable ();
+           break;      
+
        case atAddrTab:
-           AddrTable (RemainingBytes);
+           AddrTable ();
+           break;
+
+       case atRtsTab:
+           RtsTable ();
+           break;
+
+       case atTextTab:
+           TextTable ();
            break;
 
        default:
@@ -270,24 +319,25 @@ int main (int argc, char* argv [])
     /* Program long options */
     static const LongOpt OptTab[] = {
         { "--cpu",                     1,      OptCPU                  },
-       { "--formfeeds",        0,      OptFormFeeds            },
-       { "--help",             0,      OptHelp                 },
+       { "--formfeeds",        0,      OptFormFeeds            },
+       { "--help",             0,      OptHelp                 },
        { "--pagelength",       1,      OptPageLength           },
+       { "--start-addr",       1,      OptStartAddr            },
        { "--verbose",          0,      OptVerbose              },
        { "--version",          0,      OptVersion              },
     };
 
-    int I;
+    unsigned I;
 
     /* Initialize the cmdline module */
-    InitCmdLine (argc, argv, "da65");
+    InitCmdLine (&argc, &argv, "da65");
 
     /* Check the parameters */
     I = 1;
-    while (I < argc) {
+    while (I < ArgCount) {
 
                /* Get the argument */
-               const char* Arg = argv [I];
+               const char* Arg = ArgVec[I];
 
                /* Check for an option */
                if (Arg [0] == '-') {
@@ -309,6 +359,10 @@ int main (int argc, char* argv [])
                    OptVerbose (Arg, 0);
                            break;
 
+               case 'S':
+                   OptStartAddr (Arg, GetArg (&I, 2));
+                   break;
+
                        case 'V':
                    OptVersion (Arg, 0);
                            break;
@@ -352,7 +406,7 @@ int main (int argc, char* argv [])
     }
 
     /* Load the input file */
-    LoadCode (InFile, 0xE000); /* ### */
+    LoadCode (InFile, StartAddr);
 
     /* Open the output file */
     OpenOutput (OutFile);