/*****************************************************************************/
/* */
-/* output.c */
+/* output.c */
/* */
-/* Disassembler output routines */
+/* Disassembler output routines */
/* */
/* */
/* */
-/* (C) 2000-2007 Ullrich von Bassewitz */
-/* Roemerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 2000-2014, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/*****************************************************************************/
-/* Data */
+/* Data */
/*****************************************************************************/
-static FILE* F = 0; /* Output stream */
-static unsigned Col = 1; /* Current column */
-static unsigned Line = 0; /* Current line on page */
-static unsigned Page = 1; /* Current output page */
+static FILE* F = 0; /* Output stream */
+static unsigned Col = 1; /* Current column */
+static unsigned Line = 0; /* Current line on page */
+static unsigned Page = 1; /* Current output page */
+
+static const char* SegmentName = 0; /* Name of current segment */
/*****************************************************************************/
-/* Code */
+/* Code */
/*****************************************************************************/
/* Print a page header */
{
fprintf (F,
- "; da65 V%u.%u.%u - (C) Copyright 2000-2005, Ullrich von Bassewitz\n"
+ "; da65 V%s\n"
"; Created: %s\n"
- "; Input file: %s\n"
- "; Page: %u\n\n",
- VER_MAJOR, VER_MINOR, VER_PATCH,
+ "; Input file: %s\n"
+ "; Page: %u\n\n",
+ GetVersionAsString (),
Now,
- InFile,
- Page);
+ InFile,
+ Page);
}
/* Close the output file */
{
if (F != stdout && fclose (F) != 0) {
- Error ("Error closing output file: %s", strerror (errno));
+ Error ("Error closing output file: %s", strerror (errno));
}
}
/* Write to the output file */
{
if (Pass == PassCount) {
- va_list ap;
- va_start (ap, Format);
- Col += vfprintf (F, Format, ap);
- va_end (ap);
+ va_list ap;
+ va_start (ap, Format);
+ Col += vfprintf (F, Format, ap);
+ va_end (ap);
}
}
/* Make sure the current line column is at position N (zero based) */
{
if (Pass == PassCount) {
- while (Col < N) {
- fputc (' ', F);
- ++Col;
- }
+ while (Col < N) {
+ fputc (' ', F);
+ ++Col;
+ }
}
}
/* Add a linefeed to the output file */
{
if (Pass == PassCount) {
- fputc ('\n', F);
- if (PageLength > 0 && ++Line >= PageLength) {
- if (FormFeeds) {
- fputc ('\f', F);
- }
- ++Page;
- PageHeader ();
- Line = 5;
- }
- Col = 1;
+ fputc ('\n', F);
+ if (PageLength > 0 && ++Line >= PageLength) {
+ if (FormFeeds) {
+ fputc ('\f', F);
+ }
+ ++Page;
+ PageHeader ();
+ Line = 5;
+ }
+ Col = 1;
}
}
{
Output ("%s:", Name);
/* If the label is longer than the configured maximum, or if it runs into
- * the opcode column, start a new line.
- */
+ ** the opcode column, start a new line.
+ */
if (Col > LBreak+2 || Col > MCol) {
- LineFeed ();
+ LineFeed ();
}
}
void DefForward (const char* Name, const char* Comment, unsigned Offs)
/* Define a label as "* + x", where x is the offset relative to the
- * current PC.
- */
+** current PC.
+*/
{
if (Pass == PassCount) {
+ /* Flush existing output if necessary */
+ if (Col > 1) {
+ LineFeed ();
+ }
+
+ /* Output the forward definition */
Output ("%s", Name);
Indent (ACol);
if (UseHexOffs) {
-void StartSegment (const char* Name, unsigned AddrSize)
-/* Start a segment */
-{
- if (Pass == PassCount) {
- Output (".segment");
- Indent (ACol);
- if (AddrSize == ADDR_SIZE_DEFAULT) {
- Output ("\"%s\"", Name);
- } else {
- Output ("\"%s\": %s", Name, AddrSizeToStr (AddrSize));
- }
- LineFeed ();
- }
-}
-
-
-
void DataByteLine (unsigned ByteCount)
/* Output a line with bytes */
{
Output (".byte");
Indent (ACol);
for (I = 0; I < ByteCount; ++I) {
- if (I > 0) {
- Output (",$%02X", CodeBuf[PC+I]);
- } else {
- Output ("$%02X", CodeBuf[PC+I]);
- }
+ if (I > 0) {
+ Output (",$%02X", CodeBuf[PC+I]);
+ } else {
+ Output ("$%02X", CodeBuf[PC+I]);
+ }
}
LineComment (PC, ByteCount);
LineFeed ();
Output (".dbyt");
Indent (ACol);
for (I = 0; I < ByteCount; I += 2) {
- if (I > 0) {
- Output (",$%04X", GetCodeDByte (PC+I));
- } else {
- Output ("$%04X", GetCodeDByte (PC+I));
- }
+ if (I > 0) {
+ Output (",$%04X", GetCodeDByte (PC+I));
+ } else {
+ Output ("$%04X", GetCodeDByte (PC+I));
+ }
}
LineComment (PC, ByteCount);
LineFeed ();
Output (".word");
Indent (ACol);
for (I = 0; I < ByteCount; I += 2) {
- if (I > 0) {
- Output (",$%04X", GetCodeWord (PC+I));
- } else {
- Output ("$%04X", GetCodeWord (PC+I));
- }
+ if (I > 0) {
+ Output (",$%04X", GetCodeWord (PC+I));
+ } else {
+ Output ("$%04X", GetCodeWord (PC+I));
+ }
}
LineComment (PC, ByteCount);
LineFeed ();
Output (".dword");
Indent (ACol);
for (I = 0; I < ByteCount; I += 4) {
- if (I > 0) {
- Output (",$%08lX", GetCodeDWord (PC+I));
- } else {
- Output ("$%08lX", GetCodeDWord (PC+I));
- }
+ if (I > 0) {
+ Output (",$%08lX", GetCodeDWord (PC+I));
+ } else {
+ Output ("$%08lX", GetCodeDWord (PC+I));
+ }
}
LineComment (PC, ByteCount);
LineFeed ();
/* Print a separator line */
{
if (Pass == PassCount && Comments >= 1) {
- Output ("; ----------------------------------------------------------------------------");
- LineFeed ();
+ Output ("; ----------------------------------------------------------------------------");
+ LineFeed ();
}
}
+void StartSegment (const char* Name, unsigned AddrSize)
+/* Start a segment */
+{
+ if (Pass == PassCount) {
+ LineFeed ();
+ Output (".segment");
+ Indent (ACol);
+ SegmentName = Name;
+ Output ("\"%s\"", Name);
+ if (AddrSize != ADDR_SIZE_DEFAULT) {
+ Output (": %s", AddrSizeToStr (AddrSize));
+ }
+ LineFeed ();
+ LineFeed ();
+ }
+}
+
+
+
+void EndSegment (void)
+/* End a segment */
+{
+ LineFeed ();
+ Output ("; End of \"%s\" segment", SegmentName);
+ LineFeed ();
+ SeparatorLine ();
+ Output (".code");
+ LineFeed ();
+ LineFeed ();
+}
+
+
+
void UserComment (const char* Comment)
/* Output a comment line */
{
unsigned I;
if (Pass == PassCount && Comments >= 2) {
- Indent (CCol);
- Output ("; %04X", PC);
- if (Comments >= 3) {
- for (I = 0; I < Count; ++I) {
- Output (" %02X", CodeBuf [PC+I]);
- }
- if (Comments >= 4) {
- Indent (TCol);
- for (I = 0; I < Count; ++I) {
- unsigned char C = CodeBuf [PC+I];
- if (!isprint (C)) {
- C = '.';
- }
- Output ("%c", C);
- }
- }
- }
+ Indent (CCol);
+ Output ("; %04X", PC);
+ if (Comments >= 3) {
+ for (I = 0; I < Count; ++I) {
+ Output (" %02X", CodeBuf [PC+I]);
+ }
+ if (Comments >= 4) {
+ Indent (TCol);
+ for (I = 0; I < Count; ++I) {
+ unsigned char C = CodeBuf [PC+I];
+ if (!isprint (C)) {
+ C = '.';
+ }
+ Output ("%c", C);
+ }
+ }
+ }
}
}
LineFeed ();
LineFeed ();
}
-
-
-