]> git.sur5r.net Git - cc65/commitdiff
Added the main conversion module. New option --convert-to. New short options
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Fri, 9 Mar 2012 13:44:51 +0000 (13:44 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Fri, 9 Mar 2012 13:44:51 +0000 (13:44 +0000)
for --read and --write.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5586 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/sp65/convert.c [new file with mode: 0644]
src/sp65/convert.h [new file with mode: 0644]
src/sp65/main.c
src/sp65/make/gcc.mak
src/sp65/make/watcom.mak

diff --git a/src/sp65/convert.c b/src/sp65/convert.c
new file mode 100644 (file)
index 0000000..05dfce4
--- /dev/null
@@ -0,0 +1,59 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                 convert.c                                 */
+/*                                                                           */
+/*    Main target conversion module for the sp65 file and bitmap utility     */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2012,      Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+/* sp65 */
+#include "convert.h"
+#include "koala.h"
+#include "vic2sprite.h"
+
+
+
+/*****************************************************************************/
+/*                                   Code                                    */
+/*****************************************************************************/
+
+
+
+StrBuf* ConvertTo (const Bitmap* B, const Collection* A)
+/* Convert the bitmap B into some sort of other binary format. The output is
+ * stored in a string buffer (which is actually a dynamic char array) and
+ * returned. The actual output format is taken from the "format" attribute
+ * in the attribute collection A.
+ */                                                     
+{
+}
+
+
+
diff --git a/src/sp65/convert.h b/src/sp65/convert.h
new file mode 100644 (file)
index 0000000..35f9dca
--- /dev/null
@@ -0,0 +1,70 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                 convert.h                                 */
+/*                                                                           */
+/*    Main target conversion module for the sp65 file and bitmap utility     */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2012,      Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+#ifndef CONVERT_H
+#define CONVERT_H
+
+
+
+/* common */
+#include "coll.h"
+#include "strbuf.h"
+
+/* sp65 */
+#include "bitmap.h"
+
+
+
+/*****************************************************************************/
+/*                                   Code                                    */
+/*****************************************************************************/
+
+
+
+StrBuf* ConvertTo (const Bitmap* B, const Collection* A);
+/* Convert the bitmap B into some sort of other binary format. The output is
+ * stored in a string buffer (which is actually a dynamic char array) and
+ * returned. The actual output format is taken from the "format" attribute
+ * in the attribute collection A.
+ */
+
+
+
+/* End of convert.h */
+
+#endif
+
+
+
index db77b71095ccb24401a70fae244a1d67e7a4a21d..10523c7cfc8abf5bac3cce295fdb5f1dfaffab22 100644 (file)
@@ -46,6 +46,7 @@
 
 /* sp65 */
 #include "attr.h"
+#include "convert.h"
 #include "error.h"
 #include "input.h"
 #include "output.h"
 /* Bitmap first read */
 static Bitmap* B;
 
-/* Bitmap last processed */
+/* Bitmap working copy */
 static Bitmap* C;
 
+/* Output data from convertion */
+static StrBuf* D;
+
 
 
 /*****************************************************************************/
@@ -79,17 +83,21 @@ static void Usage (void)
            "Usage: %s [options] file [options] [file]\n"
            "Short options:\n"
                    "  -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"
+            "  -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"
            "\n"
            "Long options:\n"
+            "  --convert-to fmt[,attrlist]\tConvert into target format\n"
            "  --help\t\t\tHelp (this text)\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"
             "  --verbose\t\t\tIncrease verbosity\n"
                    "  --version\t\t\tPrint the version number and exit\n"
-            "  --write file[,attrlist]\tWrite an output file\n",
+            "  --write file[,attrlist]\tWrite the output to a file\n",
            ProgName);
 }
 
@@ -111,6 +119,46 @@ static void SetWorkBitmap (Bitmap* N)
 
 
 
+static void SetOutputData (StrBuf* N)
+/* Delete the old output data and replace it by the given one. The new one
+ * may be NULL to clear it.
+ */
+{
+    /* Delete the old output data */
+    if (D != 0) {
+        FreeStrBuf (D);
+    }
+
+    /* Set the new one */
+    D = N;
+}
+
+
+
+static void OptConvertTo (const char* Opt attribute ((unused)), const char* Arg)
+/* Convert the bitmap into a target format */
+{
+    static const char* NameList[] = {
+        "format"
+    };
+
+    /* Parse the argument */
+    Collection* A = ParseAttrList (Arg, NameList, 2);
+
+    /* We must have a bitmap */
+    if (C == 0) {
+        Error ("No bitmap to convert");
+    }
+
+    /* Convert the bitmap */
+    SetOutputData (ConvertTo (C, A));
+
+    /* Delete the attribute list */
+    FreeCollection (A);
+}
+
+
+
 static void OptHelp (const char* Opt attribute ((unused)),
                     const char* Arg attribute ((unused)))
 /* Print usage information and exit */
@@ -250,6 +298,9 @@ static void OptWrite (const char* Opt, const char* Arg)
 
     /* Write the file */
     WriteOutputFile (FileName, 0, OF);
+
+    /* Delete the attribute list */
+    FreeCollection (A);
 }
 
 
@@ -259,6 +310,7 @@ int main (int argc, char* argv [])
 {
     /* Program long options */
     static const LongOpt OptTab[] = {
+        { "--convert-to",       1,      OptConvertTo            },
        { "--help",             0,      OptHelp                 },
         { "--pop",              0,      OptPop                  },
         { "--read",             1,      OptRead                 },
@@ -292,6 +344,10 @@ int main (int argc, char* argv [])
                    OptVersion (Arg, 0);
                            break;
 
+                case 'c':
+                    OptConvertTo (Arg, GetArg (&I, 2));
+                    break;
+
                case 'h':
                    OptHelp (Arg, 0);
                    break;
@@ -304,6 +360,10 @@ int main (int argc, char* argv [])
                    OptVerbose (Arg, 0);
                    break;
 
+                case 'w':
+                    OptWrite (Arg, GetArg (&I, 2));
+                    break;
+
                        default:
                            UnknownOption (Arg);
                    break;
index fc54bcc28078d5ec65e02a9da52e1263515aaa45..d72a7fc163515c79dc418993e80e7e01363ab90f 100644 (file)
@@ -27,7 +27,8 @@ OBJS =        asm.o           \
         bin.o           \
         bitmap.o        \
         color.o         \
-        error.o                \
+        convert.o       \
+        error.o                \
         fileio.o        \
         input.o         \
         koala.o         \
index f3c68d190e252ce56abc695f423056b474524d6d..41b4ac6019da6e66ebd70c69722a284bb429fdd6 100644 (file)
@@ -65,7 +65,8 @@ OBJS =  asm.obj         \
         bin.obj         \
         bitmap.obj      \
         color.obj       \
-        error.obj      \
+        convert.obj     \
+        error.obj      \
         fileio.obj      \
         input.obj       \
         koala.obj       \