1 /*****************************************************************************/
5 /* Disassembler output routines */
9 /* (C) 2000-2003 Ullrich von Bassewitz */
10 /* Römerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
55 /*****************************************************************************/
57 /*****************************************************************************/
61 static FILE* F = 0; /* Output stream */
62 static unsigned Col = 1; /* Current column */
63 static unsigned Line = 0; /* Current line on page */
64 static unsigned Page = 1; /* Current output page */
68 /*****************************************************************************/
70 /*****************************************************************************/
74 static void PageHeader (void)
75 /* Print a page header */
78 "; da65 V%u.%u.%u - (C) Copyright 2000-2003 Ullrich von Bassewitz\n"
81 VER_MAJOR, VER_MINOR, VER_PATCH,
88 void OpenOutput (const char* Name)
89 /* Open the given file for output */
91 /* Open the output file */
92 F = fopen (Name, "w");
94 Error ("Cannot open `%s': %s", Name, strerror (errno));
103 void CloseOutput (void)
104 /* Close the output file */
106 if (fclose (F) != 0) {
107 Error ("Error closing output file: %s", strerror (errno));
113 void Output (const char* Format, ...)
114 /* Write to the output file */
116 if (Pass == PassCount) {
118 va_start (ap, Format);
119 Col += vfprintf (F, Format, ap);
126 void Indent (unsigned N)
127 /* Make sure the current line column is at position N (zero based) */
129 if (Pass == PassCount) {
140 /* Add a linefeed to the output file */
142 if (Pass == PassCount) {
144 if (PageLength > 0 && ++Line >= PageLength) {
158 void DefLabel (const char* Name)
159 /* Define a label with the given name */
161 Output ("%s:", Name);
162 /* Don't start a new line if the label is fully in the left column */
170 void DataByteLine (unsigned ByteCount)
171 /* Output a line with bytes */
178 for (I = 0; I < ByteCount; ++I) {
180 Output (",$%02X", CodeBuf[PC+I]);
182 Output ("$%02X", CodeBuf[PC+I]);
185 LineComment (PC, ByteCount);
191 void DataWordLine (unsigned ByteCount)
192 /* Output a line with words */
199 for (I = 0; I < ByteCount; I += 2) {
201 Output (",$%04X", GetCodeWord (PC+I));
203 Output ("$%04X", GetCodeWord (PC+I));
206 LineComment (PC, ByteCount);
212 void DataDWordLine (unsigned ByteCount)
213 /* Output a line with dwords */
220 for (I = 0; I < ByteCount; I += 4) {
222 Output (",$%08lX", GetCodeDWord (PC+I));
224 Output ("$%08lX", GetCodeDWord (PC+I));
227 LineComment (PC, ByteCount);
233 void SeparatorLine (void)
234 /* Print a separator line */
236 if (Pass == PassCount && Verbosity >= 1) {
237 Output ("; ----------------------------------------------------------------------------");
244 void LineComment (unsigned PC, unsigned Count)
245 /* Add a line comment with the PC and data bytes */
249 if (Pass == PassCount && Verbosity >= 2) {
251 Output ("; %04X", PC);
252 if (Verbosity >= 3) {
253 for (I = 0; I < Count; ++I) {
254 Output (" %02X", CodeBuf [PC+I]);
256 if (Verbosity >= 4) {
258 for (I = 0; I < Count; ++I) {
259 unsigned char C = CodeBuf [PC+I];
272 void OutputSettings (void)
273 /* Output CPU and other settings */
279 Output ("\"%s\"", CPUNames[CPU]);