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 /*****************************************************************************/
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-2003 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 /* If we have a name given, open the output file, otherwise use stdout */
92 F = fopen (Name, "w");
94 Error ("Cannot open `%s': %s", Name, strerror (errno));
100 /* Output the header and initialize stuff */
108 void CloseOutput (void)
109 /* Close the output file */
111 if (F != stdout && fclose (F) != 0) {
112 Error ("Error closing output file: %s", strerror (errno));
118 void Output (const char* Format, ...)
119 /* Write to the output file */
121 if (Pass == PassCount) {
123 va_start (ap, Format);
124 Col += vfprintf (F, Format, ap);
131 void Indent (unsigned N)
132 /* Make sure the current line column is at position N (zero based) */
134 if (Pass == PassCount) {
145 /* Add a linefeed to the output file */
147 if (Pass == PassCount) {
149 if (PageLength > 0 && ++Line >= PageLength) {
163 void DefLabel (const char* Name)
164 /* Define a label with the given name */
166 Output ("%s:", Name);
167 /* Don't start a new line if the label is fully in the left column */
175 void DataByteLine (unsigned ByteCount)
176 /* Output a line with bytes */
183 for (I = 0; I < ByteCount; ++I) {
185 Output (",$%02X", CodeBuf[PC+I]);
187 Output ("$%02X", CodeBuf[PC+I]);
190 LineComment (PC, ByteCount);
196 void DataDByteLine (unsigned ByteCount)
197 /* Output a line with dbytes */
204 for (I = 0; I < ByteCount; I += 2) {
206 Output (",$%04X", GetCodeDByte (PC+I));
208 Output ("$%04X", GetCodeDByte (PC+I));
211 LineComment (PC, ByteCount);
217 void DataWordLine (unsigned ByteCount)
218 /* Output a line with words */
225 for (I = 0; I < ByteCount; I += 2) {
227 Output (",$%04X", GetCodeWord (PC+I));
229 Output ("$%04X", GetCodeWord (PC+I));
232 LineComment (PC, ByteCount);
238 void DataDWordLine (unsigned ByteCount)
239 /* Output a line with dwords */
246 for (I = 0; I < ByteCount; I += 4) {
248 Output (",$%08lX", GetCodeDWord (PC+I));
250 Output ("$%08lX", GetCodeDWord (PC+I));
253 LineComment (PC, ByteCount);
259 void SeparatorLine (void)
260 /* Print a separator line */
262 if (Pass == PassCount && Comments >= 1) {
263 Output ("; ----------------------------------------------------------------------------");
270 void LineComment (unsigned PC, unsigned Count)
271 /* Add a line comment with the PC and data bytes */
275 if (Pass == PassCount && Comments >= 2) {
277 Output ("; %04X", PC);
279 for (I = 0; I < Count; ++I) {
280 Output (" %02X", CodeBuf [PC+I]);
284 for (I = 0; I < Count; ++I) {
285 unsigned char C = CodeBuf [PC+I];
298 void OutputSettings (void)
299 /* Output CPU and other settings */
305 Output ("\"%s\"", CPUNames[CPU]);