]> git.sur5r.net Git - cc65/blobdiff - src/sp65/main.c
Add support for 4 quadrants
[cc65] / src / sp65 / main.c
index fa1d1d6582c2c49e4c500ce7dee3b0952d6967d9..3faf1f387d83bf079f9e8b02bd49fd62fcb61028 100644 (file)
@@ -85,6 +85,7 @@ static void Usage (void)
                    "  -V\t\t\t\tPrint the version number and exit\n"
             "  -c fmt[,attrlist]\t\tConvert into target format\n"
                    "  -h\t\t\t\tHelp (this text)\n"
+            "  -lc\t\t\t\tList all possible conversions\n"
             "  -r file[,attrlist]\t\tRead an input file\n"
             "  -v\t\t\t\tIncrease verbosity\n"
             "  -w file[,attrlist]\t\tWrite the output to a file\n"
@@ -92,6 +93,7 @@ static void Usage (void)
            "Long options:\n"
             "  --convert-to fmt[,attrlist]\tConvert into target format\n"
            "  --help\t\t\tHelp (this text)\n"
+            "  --list-conversions\t\tList all possible conversions\n"
             "  --pop\t\t\t\tRestore the original loaded image\n"
             "  --read file[,attrlist]\tRead an input file\n"
             "  --slice x,y,w,h\t\tGenerate a slice from the loaded bitmap\n"
@@ -154,7 +156,27 @@ static void OptConvertTo (const char* Opt attribute ((unused)), const char* Arg)
     SetOutputData (ConvertTo (C, A));
 
     /* Delete the attribute list */
-    FreeCollection (A);
+    FreeAttrList (A);
+}
+
+
+
+static void OptDumpPalette (const char* Opt attribute ((unused)),
+                            const char* Arg attribute ((unused)))
+/* Dump the palette of the current work bitmap */
+{
+    /* We must have a bitmap ... */
+    if (C == 0) {
+        Error ("No bitmap");
+    }
+
+    /* ... which must be indexed */
+    if (!BitmapIsIndexed (C)) {
+        Error ("Current bitmap is not indexed");
+    }
+
+    /* Dump the palette */
+    DumpPalette (stdout, GetBitmapPalette (C));
 }
 
 
@@ -169,6 +191,16 @@ static void OptHelp (const char* Opt attribute ((unused)),
 
 
 
+static void OptListConversions (const char* Opt attribute ((unused)),
+                               const char* Arg attribute ((unused)))
+/* Print a list of all conversions */
+{
+    ListConversionTargets (stdout);
+    exit (EXIT_SUCCESS);
+}
+
+
+
 static void OptPop (const char* Opt attribute ((unused)),
                    const char* Arg attribute ((unused)))
 /* Restore the original image */
@@ -184,7 +216,7 @@ static void OptPop (const char* Opt attribute ((unused)),
 
 
 
-static void OptRead (const char* Opt, const char* Arg)
+static void OptRead (const char* Opt attribute ((unused)), const char* Arg)
 /* Read an input file */
 {
     static const char* NameList[] = {
@@ -195,19 +227,6 @@ static void OptRead (const char* Opt, const char* Arg)
     /* Parse the argument */
     Collection* A = ParseAttrList (Arg, NameList, 2);
 
-    /* Must have a file name given */
-    const char* FileName = NeedAttrVal (A, "name", Opt);
-
-    /* Determine the format of the input file */
-    int IF = ifAuto;
-    const char* Format = GetAttrVal (A, "format");
-    if (Format != 0) {
-        IF = FindInputFormat (Format);
-        if (IF < 0) {
-            Error ("Unknown input format `%s'", Format);
-        }
-    }
-
     /* Clear the working copy */
     SetWorkBitmap (0);
 
@@ -215,10 +234,10 @@ static void OptRead (const char* Opt, const char* Arg)
     FreeBitmap (B);
 
     /* Read the file and use it as original and as working copy */
-    B = C = ReadInputFile (FileName, IF);
+    B = C = ReadInputFile (A);
 
     /* Delete the attribute list */
-    FreeCollection (A);
+    FreeAttrList (A);
 }
 
 
@@ -272,7 +291,7 @@ static void OptVersion (const char* Opt attribute ((unused)),
 
 
 
-static void OptWrite (const char* Opt, const char* Arg)
+static void OptWrite (const char* Opt attribute ((unused)), const char* Arg)
 /* Write an output file */
 {
     static const char* NameList[] = {
@@ -283,24 +302,16 @@ static void OptWrite (const char* Opt, const char* Arg)
     /* Parse the argument */
     Collection* A = ParseAttrList (Arg, NameList, 2);
 
-    /* Must have a file name given */
-    const char* FileName = NeedAttrVal (A, "name", Opt);
-
-    /* Determine the format of the input file */
-    int OF = ofAuto;
-    const char* Format = GetAttrVal (A, "format");
-    if (Format != 0) {
-        OF = FindOutputFormat (Format);
-        if (OF < 0) {
-            Error ("Unknown output format `%s'", Format);
-        }
+    /* We must have output data */
+    if (D == 0) {
+        Error ("No conversion, so there's nothing to write");
     }
 
     /* Write the file */
-    WriteOutputFile (FileName, D, OF);
+    WriteOutputFile (D, A, C);
 
     /* Delete the attribute list */
-    FreeCollection (A);
+    FreeAttrList (A);
 }
 
 
@@ -311,7 +322,9 @@ int main (int argc, char* argv [])
     /* Program long options */
     static const LongOpt OptTab[] = {
         { "--convert-to",       1,      OptConvertTo            },
+        { "--dump-palette",     0,      OptDumpPalette          },
        { "--help",             0,      OptHelp                 },
+        { "--list-conversions", 0,      OptListConversions      },
         { "--pop",              0,      OptPop                  },
         { "--read",             1,      OptRead                 },
         { "--slice",            1,      OptSlice                },
@@ -333,24 +346,32 @@ int main (int argc, char* argv [])
                const char* Arg = ArgVec[I];
 
                /* Check for an option */
-               if (Arg [0] == '-') {
-                   switch (Arg [1]) {
+               if (Arg[0] == '-') {
+                   switch (Arg[1]) {
 
-               case '-':
-                   LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
-                   break;
+               case '-':
+                   LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
+                   break;
 
                        case 'V':
-                   OptVersion (Arg, 0);
-                           break;
+                   OptVersion (Arg, 0);
+                           break;
 
                 case 'c':
                     OptConvertTo (Arg, GetArg (&I, 2));
                     break;
 
-               case 'h':
-                   OptHelp (Arg, 0);
-                   break;
+               case 'h':
+                   OptHelp (Arg, 0);
+                   break;
+
+                case 'l':
+                    if (Arg[2] == 'c') {
+                        OptListConversions (Arg, 0);
+                    } else {
+                        UnknownOption (Arg);
+                    }
+                    break;
 
                 case 'r':
                     OptRead (Arg, GetArg (&I, 2));
@@ -378,6 +399,11 @@ int main (int argc, char* argv [])
        ++I;
     }
 
+    /* Cleanup data */
+    SetWorkBitmap (C);
+    FreeBitmap (B);
+    FreeStrBuf (D);
+
     /* Success */
     return EXIT_SUCCESS;
 }