mirror of
https://github.com/cc65/cc65.git
synced 2024-12-27 15:29:46 +00:00
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
This commit is contained in:
parent
42fb5661f1
commit
806461993b
189
src/da65/data.c
Normal file
189
src/da65/data.c
Normal file
@ -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 ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
62
src/da65/data.h
Normal file
62
src/da65/data.h
Normal file
@ -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
|
||||
|
||||
|
||||
|
@ -53,6 +53,7 @@ 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 */
|
||||
|
@ -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 */
|
||||
|
166
src/da65/main.c
166
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"
|
||||
@ -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 */
|
||||
{
|
||||
@ -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 },
|
||||
|
@ -13,6 +13,7 @@ OBJS = attrtab.o \
|
||||
code.o \
|
||||
config.o \
|
||||
cpu.o \
|
||||
data.o \
|
||||
error.o \
|
||||
global.o \
|
||||
handler.o \
|
||||
|
@ -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
|
||||
|
@ -38,6 +38,9 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user