1 /*****************************************************************************/
5 /* Disassembler output routines */
9 /* (C) 2000 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
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 /*****************************************************************************/
54 /*****************************************************************************/
56 /*****************************************************************************/
60 static FILE* F = 0; /* Output stream */
61 static unsigned Col = 1; /* Current column */
62 static unsigned Line = 0; /* Current line on page */
63 static unsigned Page = 1; /* Current output page */
67 /*****************************************************************************/
69 /*****************************************************************************/
73 static void PageHeader (void)
74 /* Print a page header */
77 "; da65 V%u.%u.%u - (C) Copyright 2000 Ullrich von Bassewitz\n"
80 VER_MAJOR, VER_MINOR, VER_PATCH,
87 void OpenOutput (const char* Name)
88 /* Open the given file for output */
90 /* Open the output file */
91 F = fopen (Name, "w");
93 Error ("Cannot open `%s': %s", Name, strerror (errno));
102 void CloseOutput (void)
103 /* Close the output file */
105 if (fclose (F) != 0) {
106 Error ("Error closing output file: %s", strerror (errno));
112 void Output (const char* Format, ...)
113 /* Write to the output file */
115 if (Pass == PassCount) {
117 va_start (ap, Format);
118 Col += vfprintf (F, Format, ap);
125 void Indent (unsigned N)
126 /* Make sure the current line column is at position N (zero based) */
128 if (Pass == PassCount) {
139 /* Add a linefeed to the output file */
141 if (Pass == PassCount) {
143 if (PageLength > 0 && ++Line >= PageLength) {
157 void DefLabel (const char* Name)
158 /* Define a label with the given name */
160 Output ("%s:", Name);
161 /* Don't start a new line if the label is fully in the left column */
169 void DataByteLine (unsigned ByteCount)
170 /* Output a line with bytes */
177 for (I = 0; I < ByteCount; ++I) {
179 Output (",$%02X", CodeBuf[PC+I]);
181 Output ("$%02X", CodeBuf[PC+I]);
184 LineComment (PC, ByteCount);
190 void DataWordLine (unsigned ByteCount)
191 /* Output a line with words */
198 for (I = 0; I < ByteCount; I += 2) {
200 Output (",$%04X", GetCodeWord (PC+I));
202 Output ("$%04X", GetCodeWord (PC+I));
205 LineComment (PC, ByteCount);
211 void DataDWordLine (unsigned ByteCount)
212 /* Output a line with dwords */
219 for (I = 0; I < ByteCount; I += 4) {
221 Output (",$%08lX", GetCodeDWord (PC+I));
223 Output ("$%08lX", GetCodeDWord (PC+I));
226 LineComment (PC, ByteCount);
232 void SeparatorLine (void)
233 /* Print a separator line */
235 if (Pass == PassCount && Verbosity >= 1) {
236 Output ("; ----------------------------------------------------------------------------");
243 void LineComment (unsigned PC, unsigned Count)
244 /* Add a line comment with the PC and data bytes */
248 if (Pass == PassCount && Verbosity >= 2) {
250 Output ("; %04X", PC);
251 if (Verbosity >= 3) {
252 for (I = 0; I < Count; ++I) {
253 Output (" %02X", CodeBuf [PC+I]);
255 if (Verbosity >= 4) {
257 for (I = 0; I < Count; ++I) {
258 unsigned char C = CodeBuf [PC+I];