1
0
mirror of https://github.com/cc65/cc65.git synced 2024-09-27 04:54:54 +00:00

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:
uz 2012-05-28 11:35:44 +00:00
parent 808f86f49f
commit 4663245219

View File

@ -116,8 +116,8 @@ static const char* GetIdentifier (const Collection* A)
/* Return the variable identifier from the attribute collection A */
{
/* Check for a ident attribute */
const char* Ident = NeedAttrVal (A, "ident", "write");
if (!ValidIdentifier (Ident)) {
const char* Ident = GetAttrVal (A, "ident");
if (Ident && !ValidIdentifier (Ident)) {
Error ("Invalid value for attribute `ident'");
}
return Ident;
@ -168,9 +168,20 @@ void WriteCFile (const StrBuf* Data, const Collection* A, const Bitmap* B)
GetBitmapColors (B),
BitmapIsIndexed (B)? ", indexed" : "");
/* Output the declaration and identifier */
fprintf (F, "const unsigned char %s[] = {\n", Ident);
/* If an identifier was given, output #defines for width, height, the
* number of colors and declare a variable for the data.
*/
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 */
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) {
switch (Base) {
case 10:
fprintf (F, "%u,", *D++);
fprintf (F, "%u,", *D++ & 0xFF);
break;
case 16:
fprintf (F, "0x%02X,", *D++);
fprintf (F, "0x%02X,", *D++ & 0xFF);
break;
}
@ -202,8 +213,10 @@ void WriteCFile (const StrBuf* Data, const Collection* A, const Bitmap* B)
Size -= Chunk;
}
/* Terminate the array */
fputs ("};\n", F);
/* Terminate the array if we had an identifier */
if (Ident) {
fputs ("};\n", F);
}
/* Close the file */
if (fclose (F) != 0) {