1 /*****************************************************************************/
5 /* Output format/file definitions for the sp65 sprite and bitmap utility */
9 /* (C) 2012, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
51 /*****************************************************************************/
53 /*****************************************************************************/
57 /* Different types of output formats */
59 ofAsm, /* Output assembler source */
60 ofBin, /* Output raw binary format */
61 ofC, /* Output C code */
63 ofCount /* Number of output formats without ofAuto */
66 typedef struct OutputFormatDesc OutputFormatDesc;
67 struct OutputFormatDesc {
70 void (*Write) (const StrBuf*, const Collection*, const Bitmap*);
74 /* Table with Output formats */
75 static OutputFormatDesc OutputFormatTable[ofCount] = {
81 /* Table that maps extensions to Output formats. Must be sorted alphabetically */
82 static const FileId FormatTable[] = {
83 /* Upper case stuff for obsolete operating systems */
101 /*****************************************************************************/
103 /*****************************************************************************/
107 void WriteOutputFile (const StrBuf* Data, const Collection* A, const Bitmap* B)
108 /* Write the contents of Data to a file. Format, file name etc. must be given
109 * as attributes in A. If no format is given, the function tries to autodetect
110 * it by using the extension of the file name. The bitmap passed to the
111 * function is the bitmap used as source of the conversion. It may be used to
112 * determine the bitmap properties for documentation purposes.
117 /* Get the file format from the command line */
118 const char* Format = GetAttrVal (A, "format");
120 /* Format is given, search for it in the table. */
123 sizeof (FormatTable) / sizeof (FormatTable[0]),
124 sizeof (FormatTable[0]),
127 Error ("Unknown output format `%s'", Format);
130 /* No format given, use file name extension */
131 const char* Name = NeedAttrVal (A, "name", "write");
132 F = GetFileId (Name, FormatTable,
133 sizeof (FormatTable) / sizeof (FormatTable[0]));
136 Error ("Cannot determine file format of output file `%s'", Name);
140 /* Call the format specific write */
141 OutputFormatTable[F->Id].Write (Data, A, B);