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 /*****************************************************************************/
53 /*****************************************************************************/
55 /*****************************************************************************/
59 static FILE* F = 0; /* Output stream */
60 static unsigned Col = 1; /* Current column */
61 static unsigned Line = 0; /* Current line on page */
62 static unsigned Page = 1; /* Current output page */
66 /*****************************************************************************/
68 /*****************************************************************************/
72 static void PageHeader (void)
73 /* Print a page header */
76 "; da65 V%u.%u.%u - (C) Copyright 2000 Ullrich von Bassewitz\n"
79 VER_MAJOR, VER_MINOR, VER_PATCH,
86 void OpenOutput (const char* Name)
87 /* Open the given file for output */
89 /* Open the output file */
90 F = fopen (Name, "w");
92 Error ("Cannot open `%s': %s", Name, strerror (errno));
101 void CloseOutput (void)
102 /* Close the output file */
104 if (fclose (F) != 0) {
105 Error ("Error closing output file: %s", strerror (errno));
111 void Output (const char* Format, ...)
112 /* Write to the output file */
114 if (Pass == PassCount) {
116 va_start (ap, Format);
117 Col += vfprintf (F, Format, ap);
124 void Indent (unsigned N)
125 /* Make sure the current line column is at position N (zero based) */
127 if (Pass == PassCount) {
138 /* Add a linefeed to the output file */
140 if (Pass == PassCount) {
142 if (++Line >= PageLength) {
156 void DefLabel (const char* Name)
157 /* Define a label with the given name */
159 Output ("%s:", Name);
160 /* Don't start a new line if the label is fully in the left column */
168 void DataByteLine (unsigned ByteCount)
169 /* Output a line with bytes */
176 for (I = 0; I < ByteCount; ++I) {
178 Output (",$%02X", CodeBuf[PC+I]);
180 Output ("$%02X", CodeBuf[PC+I]);
183 LineComment (PC, ByteCount);
189 void DataWordLine (unsigned ByteCount)
190 /* Output a line with words */
197 for (I = 0; I < ByteCount; I += 2) {
199 Output (",$%04X", GetCodeWord (PC+I));
201 Output ("$%04X", GetCodeWord (PC+I));
204 LineComment (PC, ByteCount);
210 void DataDWordLine (unsigned ByteCount)
211 /* Output a line with dwords */
218 for (I = 0; I < ByteCount; I += 4) {
220 Output (",$%08lX", GetCodeDWord (PC+I));
222 Output ("$%08lX", GetCodeDWord (PC+I));
225 LineComment (PC, ByteCount);
231 void SeparatorLine (void)
232 /* Print a separator line */
234 if (Pass == PassCount && Verbosity >= 1) {
235 Output ("; ----------------------------------------------------------------------------");
242 void LineComment (unsigned PC, unsigned Count)
243 /* Add a line comment with the PC and data bytes */
247 if (Pass == PassCount && Verbosity >= 2) {
249 Output ("; %04X", PC);
250 if (Verbosity >= 3) {
251 for (I = 0; I < Count; ++I) {
252 Output (" %02X", CodeBuf [PC+I]);
254 if (Verbosity >= 4) {
256 for (I = 0; I < Count; ++I) {
257 unsigned char C = CodeBuf [PC+I];