From: cuz Date: Mon, 25 Sep 2000 07:06:46 +0000 (+0000) Subject: Moved data output routines into a separate module. X-Git-Tag: V2.12.0~3187 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=806461993b7da9ef049c153cc474b583dca294cd;p=cc65 Moved data output routines into a separate module. Added output pagination. git-svn-id: svn://svn.cc65.org/cc65/trunk@339 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/da65/data.c b/src/da65/data.c new file mode 100644 index 000000000..97d2d7406 --- /dev/null +++ b/src/da65/data.c @@ -0,0 +1,189 @@ +/*****************************************************************************/ +/* */ +/* 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 (); + } +} + + + diff --git a/src/da65/data.h b/src/da65/data.h new file mode 100644 index 000000000..da9aaea65 --- /dev/null +++ b/src/da65/data.h @@ -0,0 +1,62 @@ +/*****************************************************************************/ +/* */ +/* 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 + + + diff --git a/src/da65/global.c b/src/da65/global.c index 328916d2c..13b6d3d4a 100644 --- a/src/da65/global.c +++ b/src/da65/global.c @@ -53,7 +53,8 @@ const char CfgExt[] = ".cfg"; /* Config file extension */ /* 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 */ diff --git a/src/da65/global.h b/src/da65/global.h index 16f5957a5..f10678307 100644 --- a/src/da65/global.h +++ b/src/da65/global.h @@ -54,6 +54,7 @@ extern const char CfgExt[]; /* Config file extension */ /* 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 */ diff --git a/src/da65/main.c b/src/da65/main.c index 1cf4188cd..c2d4ed563 100644 --- a/src/da65/main.c +++ b/src/da65/main.c @@ -50,6 +50,7 @@ #include "code.h" #include "config.h" #include "cpu.h" +#include "data.h" #include "error.h" #include "global.h" #include "opctable.h" @@ -59,7 +60,7 @@ /*****************************************************************************/ -/* Code */ +/* Code */ /*****************************************************************************/ @@ -72,30 +73,16 @@ static void Usage (void) "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); @@ -126,6 +113,14 @@ static void OptCPU (const char* Opt, const char* Arg) +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 */ { @@ -169,144 +164,6 @@ static void OptVersion (const char* Opt, const char* Arg) -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 */ { @@ -399,7 +256,7 @@ static void Disassemble (void) LineFeed (); /* Pass 2 */ - Pass = 2; + Pass = 2; ResetCode (); DefOutOfRangeLabels (); OnePass (); @@ -413,6 +270,7 @@ int main (int argc, char* argv []) /* Program long options */ static const LongOpt OptTab[] = { { "--cpu", 1, OptCPU }, + { "--formfeeds", 0, OptFormFeeds }, { "--help", 0, OptHelp }, { "--pagelength", 1, OptPageLength }, { "--verbose", 0, OptVerbose }, diff --git a/src/da65/make/gcc.mak b/src/da65/make/gcc.mak index c63345c89..638830846 100644 --- a/src/da65/make/gcc.mak +++ b/src/da65/make/gcc.mak @@ -13,6 +13,7 @@ OBJS = attrtab.o \ code.o \ config.o \ cpu.o \ + data.o \ error.o \ global.o \ handler.o \ diff --git a/src/da65/make/watcom.mak b/src/da65/make/watcom.mak index e0323ceeb..1f01073a6 100644 --- a/src/da65/make/watcom.mak +++ b/src/da65/make/watcom.mak @@ -71,6 +71,7 @@ OBJS = attrtab.obj \ code.obj \ config.obj \ cpu.obj \ + data.obj \ error.obj \ global.obj \ handler.obj \ @@ -104,6 +105,7 @@ FILE attrtab.obj FILE code.obj FILE config.obj FILE cpu.obj +FILE data.obj FILE error.obj FILE global.obj FILE handler.obj diff --git a/src/da65/output.c b/src/da65/output.c index bc10aea34..1cce284c7 100644 --- a/src/da65/output.c +++ b/src/da65/output.c @@ -38,6 +38,9 @@ #include #include +/* common */ +#include "version.h" + /* da65 */ #include "code.h" #include "error.h" @@ -54,6 +57,9 @@ 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 */ + /*****************************************************************************/ @@ -62,6 +68,20 @@ static unsigned Col = 1; /* Current column */ +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 */ { @@ -70,6 +90,9 @@ void OpenOutput (const char* Name) if (F == 0) { Error ("Cannot open `%s': %s", Name, strerror (errno)); } + PageHeader (); + Line = 4; + Col = 1; } @@ -115,6 +138,14 @@ void LineFeed (void) { if (Pass > 1) { fputc ('\n', F); + if (++Line >= PageLength) { + if (FormFeeds) { + fputc ('\f', F); + } + ++Page; + PageHeader (); + Line = 4; + } Col = 1; } }