Change data generation for C output. The ident attribute is now optional.
Without it, just the data is output. With an identifier given, there will be additional #defines for xxx_COLORS, xxx_WIDTH, xxx_HEIGHT, and the data is places into an array with the given name. git-svn-id: svn://svn.cc65.org/cc65/trunk@5662 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
31
src/sp65/c.c
31
src/sp65/c.c
@@ -116,8 +116,8 @@ static const char* GetIdentifier (const Collection* A)
|
|||||||
/* Return the variable identifier from the attribute collection A */
|
/* Return the variable identifier from the attribute collection A */
|
||||||
{
|
{
|
||||||
/* Check for a ident attribute */
|
/* Check for a ident attribute */
|
||||||
const char* Ident = NeedAttrVal (A, "ident", "write");
|
const char* Ident = GetAttrVal (A, "ident");
|
||||||
if (!ValidIdentifier (Ident)) {
|
if (Ident && !ValidIdentifier (Ident)) {
|
||||||
Error ("Invalid value for attribute `ident'");
|
Error ("Invalid value for attribute `ident'");
|
||||||
}
|
}
|
||||||
return Ident;
|
return Ident;
|
||||||
@@ -168,9 +168,20 @@ void WriteCFile (const StrBuf* Data, const Collection* A, const Bitmap* B)
|
|||||||
GetBitmapColors (B),
|
GetBitmapColors (B),
|
||||||
BitmapIsIndexed (B)? ", indexed" : "");
|
BitmapIsIndexed (B)? ", indexed" : "");
|
||||||
|
|
||||||
|
/* If an identifier was given, output #defines for width, height, the
|
||||||
/* Output the declaration and identifier */
|
* number of colors and declare a variable for the data.
|
||||||
fprintf (F, "const unsigned char %s[] = {\n", Ident);
|
*/
|
||||||
|
if (Ident) {
|
||||||
|
fprintf (F,
|
||||||
|
"#define %s_COLORS %u\n"
|
||||||
|
"#define %s_WIDTH %u\n"
|
||||||
|
"#define %s_HEIGHT %u\n"
|
||||||
|
"const unsigned char %s[] = {\n",
|
||||||
|
Ident, GetBitmapColors (B),
|
||||||
|
Ident, GetBitmapWidth (B),
|
||||||
|
Ident, GetBitmapHeight (B),
|
||||||
|
Ident);
|
||||||
|
}
|
||||||
|
|
||||||
/* Write the data */
|
/* Write the data */
|
||||||
D = SB_GetConstBuf (Data);
|
D = SB_GetConstBuf (Data);
|
||||||
@@ -188,10 +199,10 @@ void WriteCFile (const StrBuf* Data, const Collection* A, const Bitmap* B)
|
|||||||
for (I = 0; I < Chunk; ++I) {
|
for (I = 0; I < Chunk; ++I) {
|
||||||
switch (Base) {
|
switch (Base) {
|
||||||
case 10:
|
case 10:
|
||||||
fprintf (F, "%u,", *D++);
|
fprintf (F, "%u,", *D++ & 0xFF);
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
fprintf (F, "0x%02X,", *D++);
|
fprintf (F, "0x%02X,", *D++ & 0xFF);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -202,8 +213,10 @@ void WriteCFile (const StrBuf* Data, const Collection* A, const Bitmap* B)
|
|||||||
Size -= Chunk;
|
Size -= Chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Terminate the array */
|
/* Terminate the array if we had an identifier */
|
||||||
fputs ("};\n", F);
|
if (Ident) {
|
||||||
|
fputs ("};\n", F);
|
||||||
|
}
|
||||||
|
|
||||||
/* Close the file */
|
/* Close the file */
|
||||||
if (fclose (F) != 0) {
|
if (fclose (F) != 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user