#include "version.h"
/* sp65 */
+#include "attr.h"
#include "bin.h"
#include "error.h"
-void WriteAsmFile (const char* Name, const StrBuf* Data)
+void WriteAsmFile (const StrBuf* Data, const Collection* A)
/* Write the contents of Data to the given file in assembler (ca65) format */
{
+ FILE* F;
const char* D;
unsigned Size;
+ unsigned BytesPerLine = 16;
+ char C;
+
+
+ /* Get the file name */
+ const char* Name = NeedAttrVal (A, "name", "write");
+
+ /* Check for a bytesperline attribute */
+ const char* V = GetAttrVal (A, "bytesperline");
+ if ((V && sscanf (V, "%u%c", &BytesPerLine, &C) != 1) ||
+ (BytesPerLine < 1 || BytesPerLine > 64)) {
+ Error ("Invalid value for attribute `bytesperline'");
+ }
/* Open the output file */
- FILE* F = fopen (Name, "w");
+ F = fopen (Name, "w");
if (F == 0) {
Error ("Cannot open output file `%s': %s", Name, strerror (errno));
}
/* Output one line */
unsigned Chunk = Size;
- if (Chunk > 16) {
- Chunk = 16;
+ if (Chunk > BytesPerLine) {
+ Chunk = BytesPerLine;
}
fprintf (F, " .byte $%02X", (*D++ & 0xFF));
for (I = 1; I < Chunk; ++I) {
/* common */
+#include "coll.h"
#include "strbuf.h"
-void WriteAsmFile (const char* Name, const StrBuf* Data);
-/* Write the contents of Data to the given file in assembler (ca65) format */
+void WriteAsmFile (const StrBuf* Data, const Collection* A);
+/* Write the contents of Data to a file in assembler (ca65) format */
#include <string.h>
/* sp65 */
+#include "attr.h"
#include "bin.h"
#include "error.h"
-void WriteBinFile (const char* Name, const StrBuf* Data)
+void WriteBinFile (const StrBuf* Data, const Collection* A)
/* Write the contents of Data to the given file in binary format */
{
unsigned Size;
+ /* Get the file name */
+ const char* Name = NeedAttrVal (A, "name", "write");
+
/* Open the output file */
FILE* F = fopen (Name, "wb");
if (F == 0) {
/* common */
+#include "coll.h"
#include "strbuf.h"
-void WriteBinFile (const char* Name, const StrBuf* Data);
-/* Write the contents of Data to the given file in binary format */
+void WriteBinFile (const StrBuf* Data, const Collection* A);
+/* Write the contents of Data to a file in binary format */
-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[] = {
/* 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);
- }
- }
-
/* Write the file */
- WriteOutputFile (FileName, D, OF);
+ WriteOutputFile (D, A);
/* Delete the attribute list */
FreeCollection (A);
/* sp65 */
#include "asm.h"
+#include "attr.h"
#include "bin.h"
#include "error.h"
#include "output.h"
struct OutputFormatDesc {
/* Write routine */
- void (*Write) (const char* Name, const StrBuf* Data);
+ void (*Write) (const StrBuf*, const Collection*);
};
-int FindOutputFormat (const char* Name)
-/* Find an output format by name. The function returns a value less than zero
- * if Name is not a known output format.
+void WriteOutputFile (const StrBuf* Data, const Collection* A)
+/* Write the contents of Data to a file. Format, file name etc. must be given
+ * as attributes in A. If no format is given, the function tries to autodetect
+ * it by using the extension of the file name.
*/
{
- /* Search for the entry in the table. */
- const FileId* F = bsearch (Name,
- FormatTable,
- sizeof (FormatTable) / sizeof (FormatTable[0]),
- sizeof (FormatTable[0]),
- CompareFileId);
-
- /* Return the id or an error code */
- return (F == 0)? -1 : F->Id;
-}
-
-
-
-void WriteOutputFile (const char* Name, const StrBuf* Data, OutputFormat Format)
-/* Write the contents of Data to the given file in the format specified. If
- * the format is ofAuto, it is determined by the file extension.
- */
-{
- /* If the format is Auto, try to determine it from the file name */
- if (Format == ofAuto) {
- /* Search for the entry in the table */
- const FileId* F = GetFileId (Name, FormatTable,
- sizeof (FormatTable) / sizeof (FormatTable[0]));
+ const FileId* F;
+
+ /* Get the file format from the command line */
+ const char* Format = GetAttrVal (A, "format");
+ if (Format != 0) {
+ /* Format is given, search for it in the table. */
+ F = bsearch (Format,
+ FormatTable,
+ sizeof (FormatTable) / sizeof (FormatTable[0]),
+ sizeof (FormatTable[0]),
+ CompareFileId);
+ if (F == 0) {
+ Error ("Unknown output format `%s'", Format);
+ }
+ } else {
+ /* No format given, use file name extension */
+ const char* Name = NeedAttrVal (A, "name", "write");
+ F = GetFileId (Name, FormatTable,
+ sizeof (FormatTable) / sizeof (FormatTable[0]));
/* Found? */
if (F == 0) {
Error ("Cannot determine file format of output file `%s'", Name);
}
- Format = F->Id;
}
- /* Check the format just for safety */
- CHECK (Format >= 0 && Format < ofCount);
-
/* Call the format specific write */
- OutputFormatTable[Format].Write (Name, Data);
+ OutputFormatTable[F->Id].Write (Data, A);
}
-int FindOutputFormat (const char* Name);
-/* Find an output format by name. The function returns a value less than zero
- * if Name is not a known output format.
- */
-
-void WriteOutputFile (const char* Name, const StrBuf* Data, OutputFormat Format);
-/* Write the contents of Data to the given file in the format specified. If
- * the format is ofAuto, it is determined by the file extension.
+void WriteOutputFile (const StrBuf* Data, const Collection* A);
+/* Write the contents of Data to a file. Format, file name etc. must be given
+ * as attributes in A. If no format is given, the function tries to autodetect
+ * it by using the extension of the file name.
*/
/* common */
#include "attrib.h"
+#include "print.h"
/* sp65 */
#include "error.h"
StrBuf* D;
unsigned X, Y;
+
+ /* Output the image properties */
+ Print (stdout, 1, "Image is %ux%u with %u colors%s\n",
+ GetBitmapWidth (B), GetBitmapHeight (B), GetBitmapColors (B),
+ (GetBitmapType (B) == bmIndexed)? " (indexed)" : "");
+
/* Sprites pictures are always 24x21 in size with 2 colors */
if (GetBitmapType (B) != bmIndexed ||
GetBitmapColors (B) != 2 ||
GetBitmapHeight (B) != HEIGHT ||
GetBitmapWidth (B) != WIDTH) {
-
- printf ("w = %u, h = %u\n", GetBitmapWidth (B), GetBitmapHeight (B));
+
Error ("Bitmaps converted to vic2 sprite format must be in indexed "
"mode with a size of %ux%u and two colors", WIDTH, HEIGHT);
}