X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fda65%2Foutput.c;h=24977cf40ef5bd75ddfb29785bba37bdd80dfdb8;hb=dbbce2e939af8fd78f659e5c66eea8b002369ba2;hp=a655b605f6465bae1b2098bf6567d9efcc61270b;hpb=b960e3ead37575563d6b303bd6ddaa482f2252ca;p=cc65 diff --git a/src/da65/output.c b/src/da65/output.c index a655b605f..24977cf40 100644 --- a/src/da65/output.c +++ b/src/da65/output.c @@ -36,8 +36,13 @@ #include #include #include +#include #include +/* common */ +#include "print.h" +#include "version.h" + /* da65 */ #include "code.h" #include "error.h" @@ -54,6 +59,9 @@ 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 */ + /*****************************************************************************/ @@ -62,6 +70,20 @@ static unsigned Col = 1; /* Current column */ +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 */ { @@ -70,6 +92,9 @@ void OpenOutput (const char* Name) if (F == 0) { Error ("Cannot open `%s': %s", Name, strerror (errno)); } + PageHeader (); + Line = 4; + Col = 1; } @@ -87,7 +112,7 @@ void CloseOutput (void) 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); @@ -100,7 +125,7 @@ void Output (const char* Format, ...) 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; @@ -113,9 +138,17 @@ void Indent (unsigned N) 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; } } @@ -125,23 +158,73 @@ void DefLabel (const char* Name) /* 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 (); } @@ -149,10 +232,39 @@ void OneDataByte (void) 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); + } + } + } + } } -