]> git.sur5r.net Git - cc65/blobdiff - src/sp65/asm.c
Merge remote-tracking branch 'upstream/master' into a5200
[cc65] / src / sp65 / asm.c
index 4b699d40f698d68e932e323d927c2edc71e57712..8f520cb9ecdca7f301a09062c6922791660e621a 100644 (file)
@@ -45,7 +45,7 @@
 
 /* sp65 */
 #include "attr.h"
-#include "bin.h"
+#include "asm.h"
 #include "error.h"
 
 
@@ -56,7 +56,7 @@
 
 
 
-static int ValidAsmLabel (const char* L)
+static int ValidIdentifier (const char* L)
 /* Check an assembler label for validity */
 {
     /* Must begin with underscore or alphabetic character */
@@ -113,33 +113,20 @@ static unsigned GetBase (const Collection* A)
 
 
 
-static const char* GetLabel (const Collection* A)
-/* Return the assembler label from the attribute collection A */
+static const char* GetIdentifier (const Collection* A)
+/* Return the label identifier from the attribute collection A */
 {
-    /* Check for a label attribute */
-    const char* Label = GetAttrVal (A, "label");
-    if (Label && !ValidAsmLabel (Label)) {
-        Error ("Invalid value for attribute `label'");
+    /* Check for a ident attribute */
+    const char* Ident = GetAttrVal (A, "ident");
+    if (Ident && !ValidIdentifier (Ident)) {
+        Error ("Invalid value for attribute `ident'");
     }
-    return Label;
+    return Ident;
 }
 
 
 
-static const char* GetSegment (const Collection* A)
-/* Return the segment name from the attribute collection A */
-{
-    /* Check for a label attribute */
-    const char* Seg = GetAttrVal (A, "segment");
-    if (Seg && !ValidAsmLabel (Seg)) {
-        Error ("Invalid value for attribute `segment'");
-    }
-    return Seg;
-}
-
-
-
-void WriteAsmFile (const StrBuf* Data, const Collection* A)
+void WriteAsmFile (const StrBuf* Data, const Collection* A, const Bitmap* B)
 /* Write the contents of Data to the given file in assembler (ca65) format */
 {
     FILE*       F;
@@ -147,6 +134,9 @@ void WriteAsmFile (const StrBuf* Data, const Collection* A)
     unsigned    Size;
 
 
+    /* Get the name of the image */
+    const StrBuf* S = GetBitmapName (B);
+
     /* Get the file name */
     const char* Name = NeedAttrVal (A, "name", "write");
 
@@ -156,11 +146,8 @@ void WriteAsmFile (const StrBuf* Data, const Collection* A)
     /* Get the number base */
     unsigned Base = GetBase (A);
 
-    /* Get the assembler label */
-    const char* Label = GetLabel (A);
-
-    /* Get the segment */
-    const char* Segment = GetSegment (A);
+    /* Get the identifier */
+    const char* Ident = GetIdentifier (A);
 
     /* Open the output file */
     F = fopen (Name, "w");
@@ -171,21 +158,28 @@ void WriteAsmFile (const StrBuf* Data, const Collection* A)
     /* Write a readable header */
     fprintf (F,
              ";\n"
-             "; This file was generated by %s %s\n"
+             "; This file was generated by %s %s from\n"
+             "; %.*s (%ux%u, %u colors%s)\n"
              ";\n"
              "\n",
              ProgName,
-             GetVersionAsString ());
-
-
-    /* If we have a segment defined, output a segment directive */
-    if (Segment) {
-        fprintf (F, ".segment        \"%s\"\n\n", Segment);
-    }
+             GetVersionAsString (),
+             SB_GetLen (S), SB_GetConstBuf (S),
+             GetBitmapWidth (B), GetBitmapHeight (B),
+             GetBitmapColors (B),
+             BitmapIsIndexed (B)? ", indexed" : "");
 
     /* If we have an assembler label, output that */
-    if (Label) {
-        fprintf (F, "%s:\n", Label);
+    if (Ident) {
+        fprintf (F,
+                 ".proc   %s\n"
+                 "        COLORS = %u\n"
+                 "        WIDTH  = %u\n"
+                 "        HEIGHT = %u\n",
+                 Ident,
+                 GetBitmapColors (B),
+                 GetBitmapWidth (B),
+                 GetBitmapHeight (B));
     }
 
     /* Write the data */
@@ -231,6 +225,11 @@ void WriteAsmFile (const StrBuf* Data, const Collection* A)
         Size -= Chunk;
     }
 
+    /* Terminate the .proc if we had an identifier */
+    if (Ident) {
+        fputs (".endproc\n", F);
+    }
+
     /* Add an empty line at the end */
     fputc ('\n', F);
 
@@ -239,6 +238,3 @@ void WriteAsmFile (const StrBuf* Data, const Collection* A)
         Error ("Error closing output file `%s': %s", Name, strerror (errno));
     }
 }
-
-
-