#include <stdio.h>
#include <stdarg.h>
#include <string.h>
+#include <ctype.h>
#include <errno.h>
+/* common */
+#include "print.h"
+#include "version.h"
+
/* da65 */
#include "code.h"
#include "error.h"
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 void PageHeader (void)
+/* Print a page header */
+{
+ fprintf (F,
+ "; da65 V%u.%u.%u - (C) Copyright 2000 Ullrich von Bassewitz\n"
+ "; Input file: %s\n"
+ "; Page: %u\n\n",
+ VER_MAJOR, VER_MINOR, VER_PATCH,
+ InFile,
+ Page);
+}
+
+
+
void OpenOutput (const char* Name)
/* Open the given file for output */
{
if (F == 0) {
Error ("Cannot open `%s': %s", Name, strerror (errno));
}
+ PageHeader ();
+ Line = 4;
+ Col = 1;
}
void Output (const char* Format, ...)
/* Write to the output file */
{
- if (Pass > 1) {
+ if (Pass == PassCount) {
va_list ap;
va_start (ap, Format);
Col += vfprintf (F, Format, ap);
void Indent (unsigned N)
/* Make sure the current line column is at position N (zero based) */
{
- if (Pass > 1) {
+ if (Pass == PassCount) {
while (Col < N) {
fputc (' ', F);
++Col;
void LineFeed (void)
/* Add a linefeed to the output file */
{
- if (Pass > 1) {
+ if (Pass == PassCount) {
fputc ('\n', F);
- Col = 1;
+ if (PageLength > 0 && ++Line >= PageLength) {
+ if (FormFeeds) {
+ fputc ('\f', F);
+ }
+ ++Page;
+ PageHeader ();
+ Line = 4;
+ }
+ Col = 1;
}
}
/* Define a label with the given name */
{
Output ("%s:", Name);
+ /* Don't start a new line if the label is fully in the left column */
+ if (Col > MIndent) {
+ LineFeed ();
+ }
+}
+
+
+
+void DataByteLine (unsigned ByteCount)
+/* Output a line with bytes */
+{
+ unsigned I;
+
+ Indent (MIndent);
+ Output (".byte");
+ Indent (AIndent);
+ for (I = 0; I < ByteCount; ++I) {
+ if (I > 0) {
+ Output (",$%02X", CodeBuf[PC+I]);
+ } else {
+ Output ("$%02X", CodeBuf[PC+I]);
+ }
+ }
+ LineComment (PC, ByteCount);
LineFeed ();
}
-void OneDataByte (void)
-/* Output a .byte line with the current code byte */
+void DataWordLine (unsigned ByteCount)
+/* Output a line with words */
{
- unsigned char B = GetCodeByte ();
+ unsigned I;
+
+ Indent (MIndent);
+ Output (".word");
+ Indent (AIndent);
+ for (I = 0; I < ByteCount; I += 2) {
+ if (I > 0) {
+ Output (",$%04X", GetCodeWord (PC+I));
+ } else {
+ Output ("$%04X", GetCodeWord (PC+I));
+ }
+ }
+ LineComment (PC, ByteCount);
+ LineFeed ();
+}
- if (Pass > 1) {
- Indent (MIndent);
- Output (".byte");
- Indent (AIndent);
- Output ("$%02X", B);
- LineFeed ();
+
+
+void DataDWordLine (unsigned ByteCount)
+/* Output a line with dwords */
+{
+ unsigned I;
+
+ Indent (MIndent);
+ Output (".dword");
+ Indent (AIndent);
+ for (I = 0; I < ByteCount; I += 4) {
+ if (I > 0) {
+ Output (",$%08lX", GetCodeDWord (PC+I));
+ } else {
+ Output ("$%08lX", GetCodeDWord (PC+I));
+ }
}
+ LineComment (PC, ByteCount);
+ LineFeed ();
}
void SeparatorLine (void)
/* Print a separator line */
{
- Output ("; -------------------------------------------------------------------------");
- LineFeed ();
+ if (Pass == PassCount && Verbosity >= 1) {
+ Output ("; ----------------------------------------------------------------------------");
+ LineFeed ();
+ }
+}
+
+
+
+void LineComment (unsigned PC, unsigned Count)
+/* Add a line comment with the PC and data bytes */
+{
+ unsigned I;
+
+ if (Pass == PassCount && Verbosity >= 2) {
+ Indent (CIndent);
+ Output ("; %04X", PC);
+ if (Verbosity >= 3) {
+ for (I = 0; I < Count; ++I) {
+ Output (" %02X", CodeBuf [PC+I]);
+ }
+ if (Verbosity >= 4) {
+ Indent (TIndent);
+ for (I = 0; I < Count; ++I) {
+ unsigned char C = CodeBuf [PC+I];
+ if (!isprint (C)) {
+ C = '.';
+ }
+ Output ("%c", C);
+ }
+ }
+ }
+ }
}
-