--- /dev/null
+/*****************************************************************************/
+/* */
+/* data.c */
+/* */
+/* Data output routines */
+/* */
+/* */
+/* */
+/* (C) 2000 Ullrich von Bassewitz */
+/* Wacholderweg 14 */
+/* D-70597 Stuttgart */
+/* EMail: uz@musoftware.de */
+/* */
+/* */
+/* This software is provided 'as-is', without any expressed or implied */
+/* warranty. In no event will the authors be held liable for any damages */
+/* arising from the use of this software. */
+/* */
+/* Permission is granted to anyone to use this software for any purpose, */
+/* including commercial applications, and to alter it and redistribute it */
+/* freely, subject to the following restrictions: */
+/* */
+/* 1. The origin of this software must not be misrepresented; you must not */
+/* claim that you wrote the original software. If you use this software */
+/* in a product, an acknowledgment in the product documentation would be */
+/* appreciated but is not required. */
+/* 2. Altered source versions must be plainly marked as such, and must not */
+/* be misrepresented as being the original software. */
+/* 3. This notice may not be removed or altered from any source */
+/* distribution. */
+/* */
+/*****************************************************************************/
+
+
+
+/* da65 */
+#include "attrtab.h"
+#include "code.h"
+#include "error.h"
+#include "global.h"
+#include "output.h"
+#include "data.h"
+
+
+
+/*****************************************************************************/
+/* Code */
+/*****************************************************************************/
+
+
+
+void ByteTable (unsigned RemainingBytes)
+/* Output a table of bytes */
+{
+ /* Count how many bytes may be output. This number is limited by the
+ * number of remaining bytes, a label, or the end of the ByteTable
+ * attribute.
+ */
+ unsigned Count = 1;
+ while (Count < RemainingBytes) {
+ if (HaveLabel(PC+Count) || GetStyle (PC+Count) != atByteTab) {
+ break;
+ }
+ ++Count;
+ }
+ RemainingBytes -= Count;
+
+ /* Output as many data bytes lines as needed */
+ while (Count > 0) {
+
+ /* Calculate the number of bytes for the next line */
+ unsigned Chunk = (Count > BytesPerLine)? BytesPerLine : Count;
+
+ /* Output a line with these bytes */
+ DataByteLine (Chunk);
+
+ /* Next line */
+ Count -= Chunk;
+ PC += Chunk;
+ }
+
+ /* If the next line is not a byte table line, add a separator */
+ if (RemainingBytes > 0 && GetStyle (PC) != atByteTab) {
+ SeparatorLine ();
+ }
+}
+
+
+
+void WordTable (unsigned RemainingBytes)
+/* Output a table of words */
+{
+ /* Count how many bytes may be output. This number is limited by the
+ * number of remaining bytes, a label, or the end of the WordTable
+ * attribute.
+ */
+ unsigned Count = 1;
+ while (Count < RemainingBytes) {
+ if (HaveLabel(PC+Count) || GetStyle (PC+Count) != atWordTab) {
+ break;
+ }
+ ++Count;
+ }
+ RemainingBytes -= Count;
+
+ /* Make the given number even */
+ Count &= ~1U;
+
+ /* Output as many data word lines as needed */
+ while (Count > 0) {
+
+ /* Calculate the number of bytes for the next line */
+ unsigned Chunk = (Count > BytesPerLine)? BytesPerLine : Count;
+
+ /* Output a line with these bytes */
+ DataWordLine (Chunk);
+
+ /* Next line */
+ PC += Chunk;
+ Count -= Chunk;
+ }
+
+ /* If the next line is not a byte table line, add a separator */
+ if (RemainingBytes > 0 && GetStyle (PC) != atWordTab) {
+ SeparatorLine ();
+ }
+}
+
+
+
+void AddrTable (unsigned RemainingBytes)
+/* Output a table of addresses */
+{
+ /* Count how many bytes may be output. This number is limited by the
+ * number of remaining bytes, a label, or the end of the WordTable
+ * attribute.
+ */
+ unsigned Count = 1;
+ while (Count < RemainingBytes) {
+ if (HaveLabel(PC+Count) || GetStyle (PC+Count) != atAddrTab) {
+ break;
+ }
+ ++Count;
+ }
+ RemainingBytes -= Count;
+
+ /* Make the given number even */
+ Count &= ~1U;
+
+ /* Output as many data bytes lines as needed. For addresses, each line
+ * will hold just one address.
+ */
+ while (Count > 0) {
+
+ /* Get the address */
+ unsigned Addr = GetCodeWord (PC);
+
+ /* In pass 1, define a label, in pass 2 output the line */
+ if (Pass == 1) {
+ if (!HaveLabel (Addr)) {
+ AddLabel (Addr, MakeLabelName (Addr));
+ }
+ } else {
+ const char* Label = GetLabel (Addr);
+ if (Label == 0) {
+ /* OOPS! Should not happen */
+ Internal ("OOPS - Label for address %04X disappeard!", Addr);
+ }
+ Indent (MIndent);
+ Output (".word");
+ Indent (AIndent);
+ Output ("%s", Label);
+ LineComment (PC, 2);
+ LineFeed ();
+ }
+
+ /* Next line */
+ PC += 2;
+ Count -= 2;
+ }
+
+ /* If the next line is not a byte table line, add a separator */
+ if (RemainingBytes > 0 && GetStyle (PC) != atAddrTab) {
+ SeparatorLine ();
+ }
+}
+
+
+
--- /dev/null
+/*****************************************************************************/
+/* */
+/* data.h */
+/* */
+/* Data output routines */
+/* */
+/* */
+/* */
+/* (C) 2000 Ullrich von Bassewitz */
+/* Wacholderweg 14 */
+/* D-70597 Stuttgart */
+/* EMail: uz@musoftware.de */
+/* */
+/* */
+/* This software is provided 'as-is', without any expressed or implied */
+/* warranty. In no event will the authors be held liable for any damages */
+/* arising from the use of this software. */
+/* */
+/* Permission is granted to anyone to use this software for any purpose, */
+/* including commercial applications, and to alter it and redistribute it */
+/* freely, subject to the following restrictions: */
+/* */
+/* 1. The origin of this software must not be misrepresented; you must not */
+/* claim that you wrote the original software. If you use this software */
+/* in a product, an acknowledgment in the product documentation would be */
+/* appreciated but is not required. */
+/* 2. Altered source versions must be plainly marked as such, and must not */
+/* be misrepresented as being the original software. */
+/* 3. This notice may not be removed or altered from any source */
+/* distribution. */
+/* */
+/*****************************************************************************/
+
+
+
+#ifndef DATA_H
+#define DATA_H
+
+
+
+/*****************************************************************************/
+/* Code */
+/*****************************************************************************/
+
+
+
+void ByteTable (unsigned RemainingBytes);
+/* Output a table of bytes */
+
+void WordTable (unsigned RemainingBytes);
+/* Output a table of words */
+
+void AddrTable (unsigned RemainingBytes);
+/* Output a table of addresses */
+
+
+
+/* End of data.h */
+#endif
+
+
+
/* Flags and other command line stuff */
unsigned char Verbosity = 4; /* Verbosity of the output file */
-
+unsigned char FormFeeds = 0; /* Add form feeds to the output? */
+
/* Stuff needed by many routines */
unsigned Pass = 0; /* Disassembler pass */
/* Flags and other command line stuff */
extern unsigned char Verbosity; /* Verbosity of the output file */
+extern unsigned char FormFeeds; /* Add form feeds to the output? */
/* Stuff needed by many routines */
extern unsigned Pass; /* Disassembler pass */
#include "code.h"
#include "config.h"
#include "cpu.h"
+#include "data.h"
#include "error.h"
#include "global.h"
#include "opctable.h"
/*****************************************************************************/
-/* Code */
+/* Code */
/*****************************************************************************/
"Short options:\n"
" -g\t\t\tAdd debug info to object file\n"
" -h\t\t\tHelp (this text)\n"
- " -i\t\t\tIgnore case of symbols\n"
- " -l\t\t\tCreate a listing if assembly was ok\n"
" -o name\t\tName the output file\n"
- " -s\t\t\tEnable smart mode\n"
- " -t sys\t\tSet the target system\n"
" -v\t\t\tIncrease verbosity\n"
- " -D name[=value]\tDefine a symbol\n"
- " -I dir\t\tSet an include directory search path\n"
- " -U\t\t\tMark unresolved symbols as import\n"
+ " -F\t\t\tAdd formfeeds to the output\n"
" -V\t\t\tPrint the assembler version\n"
- " -W n\t\t\tSet warning level n\n"
"\n"
"Long options:\n"
- " --auto-import\t\tMark unresolved symbols as import\n"
" --cpu type\t\tSet cpu type\n"
- " --debug-info\t\tAdd debug info to object file\n"
- " --feature name\tSet an emulation feature\n"
+ " --formfeeds\t\tAdd formfeeds to the output\n"
" --help\t\tHelp (this text)\n"
- " --ignore-case\t\tIgnore case of symbols\n"
- " --include-dir dir\tSet an include directory search path\n"
- " --listing\t\tCreate a listing if assembly was ok\n"
" --pagelength n\tSet the page length for the listing\n"
- " --smart\t\tEnable smart mode\n"
- " --target sys\t\tSet the target system\n"
" --verbose\t\tIncrease verbosity\n"
" --version\t\tPrint the assembler version\n",
ProgName);
+static void OptFormFeeds (const char* Opt, const char* Arg)
+/* Add form feeds to the output */
+{
+ FormFeeds = 1;
+}
+
+
+
static void OptHelp (const char* Opt, const char* Arg)
/* Print usage information and exit */
{
-static void ByteTable (unsigned RemainingBytes)
-/* Output a table of bytes */
-{
- /* Count how many bytes may be output. This number is limited by the
- * number of remaining bytes, a label, or the end of the ByteTable
- * attribute.
- */
- unsigned Count = 1;
- while (Count < RemainingBytes) {
- if (HaveLabel(PC+Count) || GetStyle (PC+Count) != atByteTab) {
- break;
- }
- ++Count;
- }
- RemainingBytes -= Count;
-
- /* Output as many data bytes lines as needed */
- while (Count > 0) {
-
- /* Calculate the number of bytes for the next line */
- unsigned Chunk = (Count > BytesPerLine)? BytesPerLine : Count;
-
- /* Output a line with these bytes */
- DataByteLine (Chunk);
-
- /* Next line */
- Count -= Chunk;
- PC += Chunk;
- }
-
- /* If the next line is not a byte table line, add a separator */
- if (RemainingBytes > 0 && GetStyle (PC) != atByteTab) {
- SeparatorLine ();
- }
-}
-
-
-
-static void WordTable (unsigned RemainingBytes)
-/* Output a table of words */
-{
- /* Count how many bytes may be output. This number is limited by the
- * number of remaining bytes, a label, or the end of the WordTable
- * attribute.
- */
- unsigned Count = 1;
- while (Count < RemainingBytes) {
- if (HaveLabel(PC+Count) || GetStyle (PC+Count) != atWordTab) {
- break;
- }
- ++Count;
- }
- RemainingBytes -= Count;
-
- /* Make the given number even */
- Count &= ~1U;
-
- /* Output as many data word lines as needed */
- while (Count > 0) {
-
- /* Calculate the number of bytes for the next line */
- unsigned Chunk = (Count > BytesPerLine)? BytesPerLine : Count;
-
- /* Output a line with these bytes */
- DataWordLine (Chunk);
-
- /* Next line */
- PC += Chunk;
- Count -= Chunk;
- }
-
- /* If the next line is not a byte table line, add a separator */
- if (RemainingBytes > 0 && GetStyle (PC) != atWordTab) {
- SeparatorLine ();
- }
-}
-
-
-
-static void AddrTable (unsigned RemainingBytes)
-/* Output a table of addresses */
-{
- /* Count how many bytes may be output. This number is limited by the
- * number of remaining bytes, a label, or the end of the WordTable
- * attribute.
- */
- unsigned Count = 1;
- while (Count < RemainingBytes) {
- if (HaveLabel(PC+Count) || GetStyle (PC+Count) != atAddrTab) {
- break;
- }
- ++Count;
- }
- RemainingBytes -= Count;
-
- /* Make the given number even */
- Count &= ~1U;
-
- /* Output as many data bytes lines as needed. For addresses, each line
- * will hold just one address.
- */
- while (Count > 0) {
-
- /* Get the address */
- unsigned Addr = GetCodeWord (PC);
-
- /* In pass 1, define a label, in pass 2 output the line */
- if (Pass == 1) {
- if (!HaveLabel (Addr)) {
- AddLabel (Addr, MakeLabelName (Addr));
- }
- } else {
- const char* Label = GetLabel (Addr);
- if (Label == 0) {
- /* OOPS! Should not happen */
- Internal ("OOPS - Label for address %04X disappeard!", Addr);
- }
- Indent (MIndent);
- Output (".word");
- Indent (AIndent);
- Output ("%s", Label);
- LineComment (PC, 2);
- LineFeed ();
- }
-
- /* Next line */
- PC += 2;
- Count -= 2;
- }
-
- /* If the next line is not a byte table line, add a separator */
- if (RemainingBytes > 0 && GetStyle (PC) != atAddrTab) {
- SeparatorLine ();
- }
-}
-
-
-
static void OneOpcode (unsigned RemainingBytes)
/* Disassemble one opcode */
{
LineFeed ();
/* Pass 2 */
- Pass = 2;
+ Pass = 2;
ResetCode ();
DefOutOfRangeLabels ();
OnePass ();
/* Program long options */
static const LongOpt OptTab[] = {
{ "--cpu", 1, OptCPU },
+ { "--formfeeds", 0, OptFormFeeds },
{ "--help", 0, OptHelp },
{ "--pagelength", 1, OptPageLength },
{ "--verbose", 0, OptVerbose },
code.o \
config.o \
cpu.o \
+ data.o \
error.o \
global.o \
handler.o \
code.obj \
config.obj \
cpu.obj \
+ data.obj \
error.obj \
global.obj \
handler.obj \
FILE code.obj
FILE config.obj
FILE cpu.obj
+FILE data.obj
FILE error.obj
FILE global.obj
FILE handler.obj
#include <string.h>
#include <errno.h>
+/* common */
+#include "version.h"
+
/* da65 */
#include "code.h"
#include "error.h"
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 */
+
/*****************************************************************************/
+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 */
{
if (F == 0) {
Error ("Cannot open `%s': %s", Name, strerror (errno));
}
+ PageHeader ();
+ Line = 4;
+ Col = 1;
}
{
if (Pass > 1) {
fputc ('\n', F);
+ if (++Line >= PageLength) {
+ if (FormFeeds) {
+ fputc ('\f', F);
+ }
+ ++Page;
+ PageHeader ();
+ Line = 4;
+ }
Col = 1;
}
}