Move attribute lookup into the output functions. Allow a bytesperline
attribute for asm output files. git-svn-id: svn://svn.cc65.org/cc65/trunk@5589 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -42,6 +42,7 @@
|
|||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
/* sp65 */
|
/* sp65 */
|
||||||
|
#include "attr.h"
|
||||||
#include "bin.h"
|
#include "bin.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
|
||||||
@@ -53,14 +54,28 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
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 */
|
/* Write the contents of Data to the given file in assembler (ca65) format */
|
||||||
{
|
{
|
||||||
|
FILE* F;
|
||||||
const char* D;
|
const char* D;
|
||||||
unsigned Size;
|
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 */
|
/* Open the output file */
|
||||||
FILE* F = fopen (Name, "w");
|
F = fopen (Name, "w");
|
||||||
if (F == 0) {
|
if (F == 0) {
|
||||||
Error ("Cannot open output file `%s': %s", Name, strerror (errno));
|
Error ("Cannot open output file `%s': %s", Name, strerror (errno));
|
||||||
}
|
}
|
||||||
@@ -83,8 +98,8 @@ void WriteAsmFile (const char* Name, const StrBuf* Data)
|
|||||||
|
|
||||||
/* Output one line */
|
/* Output one line */
|
||||||
unsigned Chunk = Size;
|
unsigned Chunk = Size;
|
||||||
if (Chunk > 16) {
|
if (Chunk > BytesPerLine) {
|
||||||
Chunk = 16;
|
Chunk = BytesPerLine;
|
||||||
}
|
}
|
||||||
fprintf (F, " .byte $%02X", (*D++ & 0xFF));
|
fprintf (F, " .byte $%02X", (*D++ & 0xFF));
|
||||||
for (I = 1; I < Chunk; ++I) {
|
for (I = 1; I < Chunk; ++I) {
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/* common */
|
/* common */
|
||||||
|
#include "coll.h"
|
||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -49,8 +50,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
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 */
|
/* Write the contents of Data to a file in assembler (ca65) format */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* sp65 */
|
/* sp65 */
|
||||||
|
#include "attr.h"
|
||||||
#include "bin.h"
|
#include "bin.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
|
||||||
@@ -49,11 +50,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
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 */
|
/* Write the contents of Data to the given file in binary format */
|
||||||
{
|
{
|
||||||
unsigned Size;
|
unsigned Size;
|
||||||
|
|
||||||
|
/* Get the file name */
|
||||||
|
const char* Name = NeedAttrVal (A, "name", "write");
|
||||||
|
|
||||||
/* Open the output file */
|
/* Open the output file */
|
||||||
FILE* F = fopen (Name, "wb");
|
FILE* F = fopen (Name, "wb");
|
||||||
if (F == 0) {
|
if (F == 0) {
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/* common */
|
/* common */
|
||||||
|
#include "coll.h"
|
||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -49,8 +50,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
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 */
|
/* Write the contents of Data to a file in binary format */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -272,7 +272,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 */
|
/* Write an output file */
|
||||||
{
|
{
|
||||||
static const char* NameList[] = {
|
static const char* NameList[] = {
|
||||||
@@ -283,21 +283,8 @@ static void OptWrite (const char* Opt, const char* Arg)
|
|||||||
/* Parse the argument */
|
/* Parse the argument */
|
||||||
Collection* A = ParseAttrList (Arg, NameList, 2);
|
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 */
|
/* Write the file */
|
||||||
WriteOutputFile (FileName, D, OF);
|
WriteOutputFile (D, A);
|
||||||
|
|
||||||
/* Delete the attribute list */
|
/* Delete the attribute list */
|
||||||
FreeCollection (A);
|
FreeCollection (A);
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
|
|
||||||
/* sp65 */
|
/* sp65 */
|
||||||
#include "asm.h"
|
#include "asm.h"
|
||||||
|
#include "attr.h"
|
||||||
#include "bin.h"
|
#include "bin.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
@@ -56,7 +57,7 @@ typedef struct OutputFormatDesc OutputFormatDesc;
|
|||||||
struct OutputFormatDesc {
|
struct OutputFormatDesc {
|
||||||
|
|
||||||
/* Write routine */
|
/* Write routine */
|
||||||
void (*Write) (const char* Name, const StrBuf* Data);
|
void (*Write) (const StrBuf*, const Collection*);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -90,46 +91,39 @@ static const FileId FormatTable[] = {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int FindOutputFormat (const char* Name)
|
void WriteOutputFile (const StrBuf* Data, const Collection* A)
|
||||||
/* Find an output format by name. The function returns a value less than zero
|
/* Write the contents of Data to a file. Format, file name etc. must be given
|
||||||
* if Name is not a known output format.
|
* 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;
|
||||||
const FileId* F = bsearch (Name,
|
|
||||||
FormatTable,
|
|
||||||
sizeof (FormatTable) / sizeof (FormatTable[0]),
|
|
||||||
sizeof (FormatTable[0]),
|
|
||||||
CompareFileId);
|
|
||||||
|
|
||||||
/* Return the id or an error code */
|
/* Get the file format from the command line */
|
||||||
return (F == 0)? -1 : F->Id;
|
const char* Format = GetAttrVal (A, "format");
|
||||||
}
|
if (Format != 0) {
|
||||||
|
/* Format is given, search for it in the table. */
|
||||||
|
F = bsearch (Format,
|
||||||
|
FormatTable,
|
||||||
void WriteOutputFile (const char* Name, const StrBuf* Data, OutputFormat Format)
|
sizeof (FormatTable) / sizeof (FormatTable[0]),
|
||||||
/* Write the contents of Data to the given file in the format specified. If
|
sizeof (FormatTable[0]),
|
||||||
* the format is ofAuto, it is determined by the file extension.
|
CompareFileId);
|
||||||
*/
|
if (F == 0) {
|
||||||
{
|
Error ("Unknown output format `%s'", Format);
|
||||||
/* If the format is Auto, try to determine it from the file name */
|
}
|
||||||
if (Format == ofAuto) {
|
} else {
|
||||||
/* Search for the entry in the table */
|
/* No format given, use file name extension */
|
||||||
const FileId* F = GetFileId (Name, FormatTable,
|
const char* Name = NeedAttrVal (A, "name", "write");
|
||||||
sizeof (FormatTable) / sizeof (FormatTable[0]));
|
F = GetFileId (Name, FormatTable,
|
||||||
|
sizeof (FormatTable) / sizeof (FormatTable[0]));
|
||||||
/* Found? */
|
/* Found? */
|
||||||
if (F == 0) {
|
if (F == 0) {
|
||||||
Error ("Cannot determine file format of output file `%s'", Name);
|
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 */
|
/* Call the format specific write */
|
||||||
OutputFormatTable[Format].Write (Name, Data);
|
OutputFormatTable[F->Id].Write (Data, A);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -67,14 +67,10 @@ typedef enum OutputFormat OutputFormat;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int FindOutputFormat (const char* Name);
|
void WriteOutputFile (const StrBuf* Data, const Collection* A);
|
||||||
/* Find an output format by name. The function returns a value less than zero
|
/* Write the contents of Data to a file. Format, file name etc. must be given
|
||||||
* if Name is not a known output format.
|
* as attributes in A. If no format is given, the function tries to autodetect
|
||||||
*/
|
* it by using the extension of the file name.
|
||||||
|
|
||||||
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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
/* common */
|
/* common */
|
||||||
#include "attrib.h"
|
#include "attrib.h"
|
||||||
|
#include "print.h"
|
||||||
|
|
||||||
/* sp65 */
|
/* sp65 */
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
@@ -69,13 +70,18 @@ StrBuf* GenVic2Sprite (const Bitmap* B, const Collection* A attribute ((unused))
|
|||||||
StrBuf* D;
|
StrBuf* D;
|
||||||
unsigned X, Y;
|
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 */
|
/* Sprites pictures are always 24x21 in size with 2 colors */
|
||||||
if (GetBitmapType (B) != bmIndexed ||
|
if (GetBitmapType (B) != bmIndexed ||
|
||||||
GetBitmapColors (B) != 2 ||
|
GetBitmapColors (B) != 2 ||
|
||||||
GetBitmapHeight (B) != HEIGHT ||
|
GetBitmapHeight (B) != HEIGHT ||
|
||||||
GetBitmapWidth (B) != WIDTH) {
|
GetBitmapWidth (B) != WIDTH) {
|
||||||
|
|
||||||
printf ("w = %u, h = %u\n", GetBitmapWidth (B), GetBitmapHeight (B));
|
|
||||||
Error ("Bitmaps converted to vic2 sprite format must be in indexed "
|
Error ("Bitmaps converted to vic2 sprite format must be in indexed "
|
||||||
"mode with a size of %ux%u and two colors", WIDTH, HEIGHT);
|
"mode with a size of %ux%u and two colors", WIDTH, HEIGHT);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user