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:
parent
2d0e71b242
commit
c140a15dac
8 changed files with 69 additions and 65 deletions
|
@ -42,6 +42,7 @@
|
|||
#include "version.h"
|
||||
|
||||
/* sp65 */
|
||||
#include "attr.h"
|
||||
#include "bin.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 */
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
@ -83,8 +98,8 @@ void WriteAsmFile (const char* Name, const StrBuf* Data)
|
|||
|
||||
/* 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) {
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
|
||||
|
||||
/* common */
|
||||
#include "coll.h"
|
||||
#include "strbuf.h"
|
||||
|
||||
|
||||
|
@ -49,8 +50,8 @@
|
|||
|
||||
|
||||
|
||||
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 */
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include <string.h>
|
||||
|
||||
/* sp65 */
|
||||
#include "attr.h"
|
||||
#include "bin.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 */
|
||||
{
|
||||
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) {
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
|
||||
|
||||
/* common */
|
||||
#include "coll.h"
|
||||
#include "strbuf.h"
|
||||
|
||||
|
||||
|
@ -49,8 +50,8 @@
|
|||
|
||||
|
||||
|
||||
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 */
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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 */
|
||||
{
|
||||
static const char* NameList[] = {
|
||||
|
@ -283,21 +283,8 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
/* Write the file */
|
||||
WriteOutputFile (FileName, D, OF);
|
||||
WriteOutputFile (D, A);
|
||||
|
||||
/* Delete the attribute list */
|
||||
FreeCollection (A);
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
|
||||
/* sp65 */
|
||||
#include "asm.h"
|
||||
#include "attr.h"
|
||||
#include "bin.h"
|
||||
#include "error.h"
|
||||
#include "output.h"
|
||||
|
@ -56,7 +57,7 @@ typedef struct OutputFormatDesc OutputFormatDesc;
|
|||
struct OutputFormatDesc {
|
||||
|
||||
/* 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)
|
||||
/* 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,
|
||||
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);
|
||||
|
||||
/* Return the id or an error code */
|
||||
return (F == 0)? -1 : F->Id;
|
||||
if (F == 0) {
|
||||
Error ("Unknown output format `%s'", 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.
|
||||
*/
|
||||
{
|
||||
/* 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,
|
||||
} 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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -67,14 +67,10 @@ typedef enum OutputFormat OutputFormat;
|
|||
|
||||
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
|
||||
/* common */
|
||||
#include "attrib.h"
|
||||
#include "print.h"
|
||||
|
||||
/* sp65 */
|
||||
#include "error.h"
|
||||
|
@ -69,13 +70,18 @@ StrBuf* GenVic2Sprite (const Bitmap* B, const Collection* A attribute ((unused))
|
|||
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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue