From 5a90b5a58cfefaa2fbc7d72101bdb2bb1cf970be Mon Sep 17 00:00:00 2001 From: cuz Date: Sun, 24 Sep 2000 15:55:57 +0000 Subject: [PATCH] First da65 version git-svn-id: svn://svn.cc65.org/cc65/trunk@332 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/da65/attrtab.c | 177 ++++ src/da65/attrtab.h | 97 +++ src/da65/code.c | 157 ++++ src/da65/code.h | 74 ++ src/da65/cpu.c | 66 ++ src/da65/cpu.h | 75 ++ src/da65/error.c | 91 ++ src/da65/error.h | 68 ++ src/da65/global.c | 67 ++ src/da65/global.h | 76 ++ src/da65/handler.c | 392 +++++++++ src/da65/handler.h | 88 ++ src/da65/main.c | 334 ++++++++ src/da65/make/gcc.mak | 56 ++ src/da65/opctable.c | 1843 +++++++++++++++++++++++++++++++++++++++++ src/da65/opctable.h | 87 ++ src/da65/output.c | 155 ++++ src/da65/output.h | 83 ++ 18 files changed, 3986 insertions(+) create mode 100644 src/da65/attrtab.c create mode 100644 src/da65/attrtab.h create mode 100644 src/da65/code.c create mode 100644 src/da65/code.h create mode 100644 src/da65/cpu.c create mode 100644 src/da65/cpu.h create mode 100644 src/da65/error.c create mode 100644 src/da65/error.h create mode 100644 src/da65/global.c create mode 100644 src/da65/global.h create mode 100644 src/da65/handler.c create mode 100644 src/da65/handler.h create mode 100644 src/da65/main.c create mode 100644 src/da65/make/gcc.mak create mode 100644 src/da65/opctable.c create mode 100644 src/da65/opctable.h create mode 100644 src/da65/output.c create mode 100644 src/da65/output.h diff --git a/src/da65/attrtab.c b/src/da65/attrtab.c new file mode 100644 index 000000000..d19b474fb --- /dev/null +++ b/src/da65/attrtab.c @@ -0,0 +1,177 @@ +/*****************************************************************************/ +/* */ +/* attrtab.c */ +/* */ +/* Disassembler attribute table */ +/* */ +/* */ +/* */ +/* (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. */ +/* */ +/*****************************************************************************/ + + + +#include +#include + +/* common */ +#include "xmalloc.h" +#include "xsprintf.h" + +/* da65 */ +#include "error.h" +#include "attrtab.h" + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +/* Attribute table */ +static unsigned char AttrTab [0x10000]; + +/* Symbol table */ +static const char* SymTab [0x10000]; + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void AddrCheck (unsigned Addr) +/* Check if the given address has a valid range */ +{ + if (Addr >= 0x10000) { + Error ("Address out of range: %08X", Addr); + } +} + + + +void MarkRange (unsigned Start, unsigned End, attr_t Attr) +/* Mark a range with the given attribute */ +{ + /* Do it easy here... */ + while (Start <= End) { + MarkAddr (Start++, Attr); + } +} + + + +void MarkAddr (unsigned Addr, attr_t Attr) +/* Mark an address with an attribute */ +{ + /* Check the given address */ + AddrCheck (Addr); + + /* We must not have more than one style bit */ + if (Attr & atStyleMask) { + if (AttrTab[Addr] & atStyleMask) { + Error ("Duplicate style for address %04X", Addr); + } + } + + /* Set the style */ + AttrTab[Addr] |= Attr; +} + + + +const char* MakeLabelName (unsigned Addr) +/* Make the default label name from the given address and return it in a + * static buffer. + */ +{ + static char LabelBuf [32]; + xsprintf (LabelBuf, sizeof (LabelBuf), "L%04X", Addr); + return LabelBuf; +} + + + +void AddLabel (unsigned Addr, const char* Name) +/* Add a label */ +{ + /* Check the given address */ + AddrCheck (Addr); + + /* Must not have two symbols for one address */ + if (SymTab[Addr] != 0) { + if (strcmp (SymTab[Addr], Name) == 0) { + /* Allow label if it has the same name */ + return; + } + Error ("Duplicate label for address %04X: %s/%s", Addr, SymTab[Addr], Name); + } + + /* Create a new label */ + SymTab[Addr] = xstrdup (Name); +} + + + +int HaveLabel (unsigned Addr) +/* Check if there is a label for the given address */ +{ + /* Check the given address */ + AddrCheck (Addr); + + /* Check for a label */ + return (SymTab[Addr] != 0); +} + + + +const char* GetLabel (unsigned Addr) +/* Return the label for an address */ +{ + /* Check the given address */ + AddrCheck (Addr); + + /* Return the label if any */ + return SymTab[Addr]; +} + + + +unsigned char GetStyle (unsigned Addr) +/* Return the style attribute for the given address */ +{ + /* Check the given address */ + AddrCheck (Addr); + + /* Return the attribute */ + return (AttrTab[Addr] & atStyleMask); +} + + + diff --git a/src/da65/attrtab.h b/src/da65/attrtab.h new file mode 100644 index 000000000..1c504df38 --- /dev/null +++ b/src/da65/attrtab.h @@ -0,0 +1,97 @@ +/*****************************************************************************/ +/* */ +/* attrtab.h */ +/* */ +/* Disassembler attribute table */ +/* */ +/* */ +/* */ +/* (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 ATTRTAB_H +#define ATTRTAB_H + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +typedef enum attr_t attr_t; +enum attr_t { + atDefault = 0x00, /* Default style */ + atCode = 0x01, + atIllegal = 0x02, + atByteTab = 0x02, /* Same as illegal */ + atWordTab = 0x04, + atRtsTab = 0x08, + atLabel = 0x80, + + atStyleMask = 0x0F /* Output style */ +}; + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void MarkRange (unsigned Start, unsigned End, attr_t Attr); +/* Mark a range with the given attribute */ + +void MarkAddr (unsigned Addr, attr_t Attr); +/* Mark an address with an attribute */ + +const char* MakeLabelName (unsigned Addr); +/* Make the default label name from the given address and return it in a + * static buffer. + */ + +void AddLabel (unsigned Addr, const char* Name); +/* Add a label */ + +int HaveLabel (unsigned Addr); +/* Check if there is a label for the given address */ + +const char* GetLabel (unsigned Addr); +/* Return the label for an address */ + +unsigned char GetStyle (unsigned Addr); +/* Return the style attribute for the given address */ + + + +/* End of attrtab.h */ +#endif + + + diff --git a/src/da65/code.c b/src/da65/code.c new file mode 100644 index 000000000..ff031d0aa --- /dev/null +++ b/src/da65/code.c @@ -0,0 +1,157 @@ +/*****************************************************************************/ +/* */ +/* code.c */ +/* */ +/* Binary code management */ +/* */ +/* */ +/* */ +/* (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. */ +/* */ +/*****************************************************************************/ + + + +#include +#include +#include + +/* common */ +#include "check.h" + +/* da65 */ +#include "error.h" +#include "code.h" + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +static unsigned char CodeBuf [0x10000]; /* Code buffer */ +static unsigned long CodeStart; /* Start address */ +static unsigned long CodeEnd; /* End address */ +static unsigned long PC; /* Current PC */ + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void LoadCode (const char* Name, unsigned long StartAddress) +/* Load the code from the given file */ +{ + unsigned Count, MaxCount; + FILE* F; + + + PRECONDITION (StartAddress < 0x10000); + + /* Calculate the maximum code size */ + MaxCount = 0x10000 - StartAddress; + + /* Open the file */ + F = fopen (Name, "rb"); + if (F == 0) { + Error ("Cannot open `%s': %s", Name, strerror (errno)); + } + + /* Read from the file and remember the number of bytes read */ + Count = fread (CodeBuf + StartAddress, 1, MaxCount, F); + if (ferror (F)) { + Error ("Error reading from `%s': %s", Name, strerror (errno)); + } + if (Count == 0) { + Error ("File `%s' contains no data", Name); + } + + /* Set the buffer variables */ + CodeStart = PC = StartAddress; + CodeEnd = CodeStart + Count - 1; /* CodeEnd is inclusive */ +} + + + +unsigned GetPC (void) +/* Get the current program counter */ +{ + return PC; +} + + + +unsigned char PeekCodeByte (void) +/* Peek at the byte at the current PC */ +{ + PRECONDITION (PC <= CodeEnd); + return CodeBuf [PC]; +} + + + +unsigned char GetCodeByte (void) +/* Get a byte from the PC and increment it */ +{ + PRECONDITION (PC <= CodeEnd); + return CodeBuf [PC++]; +} + + + +unsigned GetCodeWord (void) +/* Get a word from the current PC and increment it */ +{ + unsigned Lo = GetCodeByte (); + unsigned Hi = GetCodeByte (); + return Lo | (Hi << 8); +} + + + +unsigned GetRemainingBytes (void) +/* Return the number of remaining code bytes */ +{ + if (CodeEnd >= PC) { + return (CodeEnd - PC + 1); + } else { + return 0; + } +} + + + +void ResetCode (void) +/* Reset the code input to start over for the next pass */ +{ + PC = CodeStart; +} + + + diff --git a/src/da65/code.h b/src/da65/code.h new file mode 100644 index 000000000..1e7a47702 --- /dev/null +++ b/src/da65/code.h @@ -0,0 +1,74 @@ +/*****************************************************************************/ +/* */ +/* code.h */ +/* */ +/* Binary code management */ +/* */ +/* */ +/* */ +/* (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 CODE_H +#define CODE_H + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void LoadCode (const char* Name, unsigned long StartAddress); +/* Load the code from the given file */ + +unsigned GetPC (void); +/* Get the current program counter */ + +unsigned char PeekCodeByte (void); +/* Peek at the byte at the current PC */ + +unsigned char GetCodeByte (void); +/* Get a byte from the PC and increment it */ + +unsigned GetCodeWord (void); +/* Get a word from the current PC and increment it */ + +unsigned GetRemainingBytes (void); +/* Return the number of remaining code bytes */ + +void ResetCode (void); +/* Reset the code input to start over for the next pass */ + + + +/* End of code.h */ +#endif + + + diff --git a/src/da65/cpu.c b/src/da65/cpu.c new file mode 100644 index 000000000..b772b3fbb --- /dev/null +++ b/src/da65/cpu.c @@ -0,0 +1,66 @@ +/*****************************************************************************/ +/* */ +/* cpu.c */ +/* */ +/* CPU type definitions */ +/* */ +/* */ +/* */ +/* (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. */ +/* */ +/*****************************************************************************/ + + + +#include "cpu.h" + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +/* Current CPU */ +CPUType CPU = CPU_6502; + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void SetCPU (CPUType NewCPU) +/* Set a new CPU */ +{ + CPU = NewCPU; +} + + + + + diff --git a/src/da65/cpu.h b/src/da65/cpu.h new file mode 100644 index 000000000..3d2210ec0 --- /dev/null +++ b/src/da65/cpu.h @@ -0,0 +1,75 @@ +/*****************************************************************************/ +/* */ +/* cpu.h */ +/* */ +/* CPU type definitions */ +/* */ +/* */ +/* */ +/* (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 CPU_H +#define CPU_H + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +/* Supported CPUs */ +typedef enum CPUType { + CPU_6502, + CPU_65C02, + CPU_65816 +} CPUType; + +/* Current CPU */ +extern CPUType CPU; + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void SetCPU (CPUType NewCPU); +/* Set a new CPU */ + + + +/* End of cpu.h */ + +#endif + + + diff --git a/src/da65/error.c b/src/da65/error.c new file mode 100644 index 000000000..0b52dee45 --- /dev/null +++ b/src/da65/error.c @@ -0,0 +1,91 @@ +/*****************************************************************************/ +/* */ +/* error.c */ +/* */ +/* Error handling */ +/* */ +/* */ +/* */ +/* (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. */ +/* */ +/*****************************************************************************/ + + + +#include +#include +#include + +/* da65 */ +#include "error.h" + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void Warning (const char* Format, ...) +/* Print a warning message */ +{ + va_list ap; + va_start (ap, Format); + fprintf (stderr, "Warning: "); + vfprintf (stderr, Format, ap); + putc ('\n', stderr); + va_end (ap); +} + + + +void Error (const char* Format, ...) +/* Print an error message and die */ +{ + va_list ap; + va_start (ap, Format); + fprintf (stderr, "Error: "); + vfprintf (stderr, Format, ap); + putc ('\n', stderr); + va_end (ap); + exit (EXIT_FAILURE); +} + + + +void Internal (const char* Format, ...) +/* Print an internal error message and die */ +{ + va_list ap; + va_start (ap, Format); + fprintf (stderr, "Internal error: "); + vfprintf (stderr, Format, ap); + putc ('\n', stderr); + va_end (ap); + exit (EXIT_FAILURE); +} + + + diff --git a/src/da65/error.h b/src/da65/error.h new file mode 100644 index 000000000..c75d96bd1 --- /dev/null +++ b/src/da65/error.h @@ -0,0 +1,68 @@ +/*****************************************************************************/ +/* */ +/* error.h */ +/* */ +/* Error handling */ +/* */ +/* */ +/* */ +/* (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 ERROR_H +#define ERROR_H + + + +/* common */ +#include "attrib.h" + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void Warning (const char* Format, ...) attribute((format(printf,1,2))); +/* Print a warning message */ + +void Error (const char* Format, ...) attribute((format(printf,1,2))); +/* Print an error message and die */ + +void Internal (const char* Format, ...) attribute((format(printf,1,2))); +/* Print an internal error message and die */ + + + +/* End of error.h */ + +#endif + + + diff --git a/src/da65/global.c b/src/da65/global.c new file mode 100644 index 000000000..3e99ec8c3 --- /dev/null +++ b/src/da65/global.c @@ -0,0 +1,67 @@ +/*****************************************************************************/ +/* */ +/* global.c */ +/* */ +/* Global variables for the da65 disassembler */ +/* */ +/* */ +/* */ +/* (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. */ +/* */ +/*****************************************************************************/ + + + +#include "global.h" + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +/* File names */ +const char* InFile = 0; /* Name of input file */ +const char* OutFile = 0; /* Name of output file */ + +/* Default extensions */ +const char ObjExt[] = ".o"; /* Default object extension */ +const char ListExt[] = ".lst"; /* Default listing extension */ + +/* Flags and other command line stuff */ +unsigned char Verbose = 2; /* Verbosity of the output file */ + +/* Stuff needed by many routines */ +unsigned Pass = 0; /* Disassembler pass */ + +/* Page formatting */ +int PageLength = -1; /* Length of a listing page */ +unsigned MIndent = 9; /* Mnemonic indent */ +unsigned AIndent = 17; /* Argument indent */ +unsigned CIndent = 33; /* Comment indent */ + + + diff --git a/src/da65/global.h b/src/da65/global.h new file mode 100644 index 000000000..0af03cdd3 --- /dev/null +++ b/src/da65/global.h @@ -0,0 +1,76 @@ +/*****************************************************************************/ +/* */ +/* global.h */ +/* */ +/* Global variables for the da65 disassembler */ +/* */ +/* */ +/* */ +/* (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 GLOBAL_H +#define GLOBAL_H + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +/* File names */ +extern const char* InFile; /* Name of input file */ +extern const char* OutFile; /* Name of output file */ + +/* Default extensions */ +extern const char ObjExt[]; /* Default object extension */ +extern const char ListExt[]; /* Default listing extension */ + +/* Flags and other command line stuff */ +extern unsigned char Verbose; /* Verbosity of the output file */ + +/* Stuff needed by many routines */ +extern unsigned Pass; /* Disassembler pass */ + +/* Page formatting */ +#define MIN_PAGE_LEN 32 +#define MAX_PAGE_LEN 127 +extern int PageLength; /* Length of a listing page */ +extern unsigned MIndent; /* Mnemonic indent */ +extern unsigned AIndent; /* Argument indent */ +extern unsigned CIndent; /* Comment indent */ + + + +/* End of global.h */ + +#endif + + + diff --git a/src/da65/handler.c b/src/da65/handler.c new file mode 100644 index 000000000..ab1bda3f6 --- /dev/null +++ b/src/da65/handler.c @@ -0,0 +1,392 @@ +/*****************************************************************************/ +/* */ +/* handler.c */ +/* */ +/* Opcode handler functions for the disassembler */ +/* */ +/* */ +/* */ +/* (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. */ +/* */ +/*****************************************************************************/ + + + +#include + +/* common */ +#include "xsprintf.h" + +/* da65 */ +#include "attrtab.h" +#include "code.h" +#include "error.h" +#include "global.h" +#include "opctable.h" +#include "output.h" +#include "handler.h" + + + +/*****************************************************************************/ +/* Helper functions */ +/*****************************************************************************/ + + + +static void Mnemonic (const char* M) +/* Indent and output a mnemonic */ +{ + Indent (MIndent); + Output ("%s", M); +} + + + +static void OneLine (const char* Mnemo, const char* Arg, ...) attribute ((format(printf, 2, 3))); +static void OneLine (const char* Mnemo, const char* Arg, ...) +/* Output one line with the given mnemonic and argument */ +{ + char Buf [256]; + va_list ap; + + /* Mnemonic */ + Mnemonic (Mnemo); + + /* Argument */ + va_start (ap, Arg); + xvsprintf (Buf, sizeof (Buf), Arg, ap); + va_end (ap); + Indent (AIndent); + Output (Buf); + + /* End the line */ + LineFeed (); +} + + + +static const char* GetAddrArg (const OpcDesc* D, unsigned Addr) +/* Return an address argument - a label if we have one, or the address itself */ +{ + const char* Label = 0; + if (D->LabelFlag & lfUseLabel) { + Label = GetLabel (Addr); + } + if (Label) { + return Label; + } else { + static char Buf [32]; + if (Addr < 0x100) { + xsprintf (Buf, sizeof (Buf), "$%02X", Addr); + } else { + xsprintf (Buf, sizeof (Buf), "$%04X", Addr); + } + return Buf; + } +} + + + +static void GenerateLabel (const OpcDesc* D, unsigned Addr) +/* Generate a label in pass one if requested */ +{ + if (Pass == 1 && !HaveLabel (Addr) && (D->LabelFlag & lfGenLabel) != 0) { + AddLabel (Addr, MakeLabelName (Addr)); + } +} + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void OH_Accumulator (const OpcDesc* D) +{ + OneLine (D->Mnemo, "a"); +} + + + +void OH_Implicit (const OpcDesc* D) +{ + Mnemonic (D->Mnemo); + LineFeed (); +} + + + +void OH_Immidiate (const OpcDesc* D) +{ + OneLine (D->Mnemo, "#$%02X", GetCodeByte ()); +} + + + +void OH_Direct (const OpcDesc* D) +{ + /* Get the operand */ + unsigned Addr = GetCodeByte (); + + /* Generate a label in pass 1 */ + GenerateLabel (D, Addr); + + /* Output the line */ + OneLine (D->Mnemo, "%s", GetAddrArg (D, Addr)); +} + + + +void OH_DirectX (const OpcDesc* D) +{ + /* Get the operand */ + unsigned Addr = GetCodeByte (); + + /* Generate a label in pass 1 */ + GenerateLabel (D, Addr); + + /* Output the line */ + OneLine (D->Mnemo, "%s,y", GetAddrArg (D, Addr)); +} + + + +void OH_DirectY (const OpcDesc* D) +{ + /* Get the operand */ + unsigned Addr = GetCodeByte (); + + /* Generate a label in pass 1 */ + GenerateLabel (D, Addr); + + /* Output the line */ + OneLine (D->Mnemo, "%s,y", GetAddrArg (D, Addr)); +} + + + +void OH_Absolute (const OpcDesc* D) +{ + /* Get the operand */ + unsigned Addr = GetCodeWord (); + + /* Generate a label in pass 1 */ + GenerateLabel (D, Addr); + + /* Output the line */ + OneLine (D->Mnemo, "%s", GetAddrArg (D, Addr)); +} + + + +void OH_AbsoluteX (const OpcDesc* D) +{ + /* Get the operand */ + unsigned Addr = GetCodeWord (); + + /* Generate a label in pass 1 */ + GenerateLabel (D, Addr); + + /* Output the line */ + OneLine (D->Mnemo, "%s,x", GetAddrArg (D, Addr)); +} + + + +void OH_AbsoluteY (const OpcDesc* D) +{ + /* Get the operand */ + unsigned Addr = GetCodeWord (); + + /* Generate a label in pass 1 */ + GenerateLabel (D, Addr); + + /* Output the line */ + OneLine (D->Mnemo, "%s,y", GetAddrArg (D, Addr)); +} + + + +void OH_AbsoluteLong (const OpcDesc* D) +{ + Error ("Not implemented"); +} + + + +void OH_AbsoluteLongX (const OpcDesc* D) +{ + Error ("Not implemented"); +} + + + +void OH_Relative (const OpcDesc* D) +{ + /* Get the operand */ + signed char Offs = GetCodeByte (); + + /* Calculate the target address */ + unsigned Addr = (unsigned) (((int) GetPC()) + Offs); + + /* Generate a label in pass 1 */ + GenerateLabel (D, Addr); + + /* Output the line */ + OneLine (D->Mnemo, "%s", GetAddrArg (D, Addr)); +} + + + +void OH_RelativeLong (const OpcDesc* D) +{ + Error ("Not implemented"); +} + + + +void OH_DirectIndirect (const OpcDesc* D) +{ + /* Get the operand */ + unsigned Addr = GetCodeByte (); + + /* Generate a label in pass 1 */ + GenerateLabel (D, Addr); + + /* Output the line */ + OneLine (D->Mnemo, "(%s)", GetAddrArg (D, Addr)); +} + + + +void OH_DirectIndirectY (const OpcDesc* D) +{ + /* Get the operand */ + unsigned Addr = GetCodeByte (); + + /* Generate a label in pass 1 */ + GenerateLabel (D, Addr); + + /* Output the line */ + OneLine (D->Mnemo, "(%s),y", GetAddrArg (D, Addr)); +} + + + +void OH_DirectXIndirect (const OpcDesc* D) +{ + /* Get the operand */ + unsigned Addr = GetCodeByte (); + + /* Generate a label in pass 1 */ + GenerateLabel (D, Addr); + + /* Output the line */ + OneLine (D->Mnemo, "(%s,x)", GetAddrArg (D, Addr)); +} + + + +void OH_AbsoluteIndirect (const OpcDesc* D) +{ + /* Get the operand */ + unsigned Addr = GetCodeWord (); + + /* Generate a label in pass 1 */ + GenerateLabel (D, Addr); + + /* Output the line */ + OneLine (D->Mnemo, "(%s)", GetAddrArg (D, Addr)); +} + + + +void OH_StackRelative (const OpcDesc* D) +{ + Error ("Not implemented"); +} + + + +void OH_DirectIndirectLongX (const OpcDesc* D) +{ + Error ("Not implemented"); +} + + + +void OH_StackRelativeIndirectY (const OpcDesc* D) +{ + Error ("Not implemented"); +} + + + +void OH_DirectIndirectLong (const OpcDesc* D) +{ + Error ("Not implemented"); +} + + + +void OH_DirectIndirectLongY (const OpcDesc* D) +{ + Error ("Not implemented"); +} + + + +void OH_BlockMove (const OpcDesc* D) +{ + Error ("Not implemented"); +} + + + +void OH_AbsoluteXIndirect (const OpcDesc* D) +{ + Error ("Not implemented"); +} + + + +void OH_Rts (const OpcDesc* D) +{ + OH_Implicit (D); + SeparatorLine(); +} + + + +void OH_JmpAbsolute (const OpcDesc* D) +{ + OH_Absolute (D); + SeparatorLine (); +} + + + diff --git a/src/da65/handler.h b/src/da65/handler.h new file mode 100644 index 000000000..e33ba113e --- /dev/null +++ b/src/da65/handler.h @@ -0,0 +1,88 @@ +/*****************************************************************************/ +/* */ +/* handler.h */ +/* */ +/* Opcode handler functions for the disassembler */ +/* */ +/* */ +/* */ +/* (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 HANDLER_H +#define HANDLER_H + + + +#include "opctable.h" + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +/* Generic handlers */ +void OH_Accumulator (const OpcDesc*); +void OH_Implicit (const OpcDesc*); +void OH_Immidiate (const OpcDesc*); +void OH_Direct (const OpcDesc*); +void OH_DirectX (const OpcDesc*); +void OH_DirectY (const OpcDesc*); +void OH_Absolute (const OpcDesc*); +void OH_AbsoluteX (const OpcDesc*); +void OH_AbsoluteY (const OpcDesc*); +void OH_AbsoluteLong (const OpcDesc*); +void OH_AbsoluteLongX (const OpcDesc*); +void OH_Relative (const OpcDesc*); +void OH_RelativeLong (const OpcDesc*); +void OH_DirectIndirect (const OpcDesc*); +void OH_DirectIndirectY (const OpcDesc*); +void OH_DirectXIndirect (const OpcDesc*); +void OH_AbsoluteIndirect (const OpcDesc*); + +void OH_StackRelative (const OpcDesc*); +void OH_DirectIndirectLongX (const OpcDesc*); +void OH_StackRelativeIndirectY (const OpcDesc*); +void OH_DirectIndirectLong (const OpcDesc*); +void OH_DirectIndirectLongY (const OpcDesc*); +void OH_BlockMove (const OpcDesc*); +void OH_AbsoluteXIndirect (const OpcDesc*); + +/* Handlers for special instructions */ +void OH_Rts (const OpcDesc*); +void OH_JmpAbsolute (const OpcDesc*); + + + +/* End of handler.h */ +#endif + + + diff --git a/src/da65/main.c b/src/da65/main.c new file mode 100644 index 000000000..c343a6444 --- /dev/null +++ b/src/da65/main.c @@ -0,0 +1,334 @@ +/*****************************************************************************/ +/* */ +/* main.c */ +/* */ +/* Main program for the da65 disassembler */ +/* */ +/* */ +/* */ +/* (C) 1998-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. */ +/* */ +/*****************************************************************************/ + + + +#include +#include +#include +#include +#include + +/* common */ +#include "abend.h" +#include "cmdline.h" +#include "fname.h" +#include "version.h" + +/* da65 */ +#include "attrtab.h" +#include "code.h" +#include "cpu.h" +#include "global.h" +#include "opctable.h" +#include "output.h" + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +static void Usage (void) +/* Print usage information and exit */ +{ + fprintf (stderr, + "Usage: %s [options] file\n" + "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" + " -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" + " --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 OptCPU (const char* Opt, const char* Arg) +/* Handle the --cpu option */ +{ + if (Arg == 0) { + NeedArg (Opt); + } + if (strcmp (Arg, "6502") == 0) { + SetCPU (CPU_6502); + } else if (strcmp (Arg, "65C02") == 0) { + SetCPU (CPU_65C02); + } else if (strcmp (Arg, "65816") == 0) { + SetCPU (CPU_65816); +#ifdef SUNPLUS + } else if (strcmp (Arg, "sunplus") == 0) { + SetCPU (CPU_SUNPLUS); +#endif + } else { + AbEnd ("Invalid CPU: `%s'", Arg); + } +} + + + +static void OptHelp (const char* Opt, const char* Arg) +/* Print usage information and exit */ +{ + Usage (); + exit (EXIT_SUCCESS); +} + + + +static void OptPageLength (const char* Opt, const char* Arg) +/* Handle the --pagelength option */ +{ + int Len; + if (Arg == 0) { + NeedArg (Opt); + } + Len = atoi (Arg); + if (Len != -1 && (Len < MIN_PAGE_LEN || Len > MAX_PAGE_LEN)) { + AbEnd ("Invalid page length: %d", Len); + } + PageLength = Len; +} + + + +static void OptVerbose (const char* Opt, const char* Arg) +/* Increase verbosity */ +{ + ++Verbose; +} + + + +static void OptVersion (const char* Opt, const char* Arg) +/* Print the disassembler version */ +{ + fprintf (stderr, + "da65 V%u.%u.%u - (C) Copyright 2000 Ullrich von Bassewitz\n", + VER_MAJOR, VER_MINOR, VER_PATCH); +} + + + +static void OneOpcode (unsigned RemainingBytes) +/* Disassemble one opcode */ +{ + /* Get the current PC */ + unsigned PC = GetPC (); + + /* Get the attribute for the current address */ + unsigned char Style = GetStyle (PC); + + /* Get the opcode from the current address */ + unsigned char OPC = PeekCodeByte (); + + /* Get the opcode description for the opcode byte */ + const OpcDesc* D = &OpcTable[OPC]; + + /* If we have a label at this address, output the label */ + const char* Label = GetLabel (PC); + if (Label) { + DefLabel (Label); + } + + /* Check if we have enough bytes remaining for the code at this address. */ + if (D->Size > RemainingBytes) { + OneDataByte (); + return; + } + + /* Also check if there are any labels that point into this instruction. + * If so, disassemble one byte as data. + */ + /* ### */ + + /* Disassemble the line */ + GetCodeByte (); + D->Handler (D); +} + + + +static void OnePass (void) +/* Make one pass through the code */ +{ + unsigned Count; + + /* Disassemble until nothing left */ + while ((Count = GetRemainingBytes()) > 0) { + OneOpcode (Count); + } +} + + + +static void Disassemble (void) +/* Disassemble the code */ +{ + /* Pass 1 */ + Pass = 1; + OnePass (); + + Output ("---------------------------"); + LineFeed (); + + /* Pass 2 */ + ResetCode (); + Pass = 2; + OnePass (); +} + + + +int main (int argc, char* argv []) +/* Assembler main program */ +{ + /* Program long options */ + static const LongOpt OptTab[] = { + { "--cpu", 1, OptCPU }, + { "--help", 0, OptHelp }, + { "--pagelength", 1, OptPageLength }, + { "--verbose", 0, OptVerbose }, + { "--version", 0, OptVersion }, + }; + + int I; + + /* Initialize the cmdline module */ + InitCmdLine (argc, argv, "da65"); + + /* Check the parameters */ + I = 1; + while (I < argc) { + + /* Get the argument */ + const char* Arg = argv [I]; + + /* Check for an option */ + if (Arg [0] == '-') { + switch (Arg [1]) { + + case '-': + LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0])); + break; + + case 'h': + OptHelp (Arg, 0); + break; + + case 'o': + OutFile = GetArg (&I, 2); + break; + + case 'v': + OptVerbose (Arg, 0); + break; + + case 'V': + OptVersion (Arg, 0); + break; + + default: + UnknownOption (Arg); + break; + + } + } else { + /* Filename. Check if we already had one */ + if (InFile) { + fprintf (stderr, "%s: Don't know what to do with `%s'\n", + ProgName, Arg); + exit (EXIT_FAILURE); + } else { + InFile = Arg; + } + } + + /* Next argument */ + ++I; + } + + /* Must have an input file */ + if (InFile == 0) { + AbEnd ("No input file"); + } + + /* Make the output file name from the input file name if none was given */ + if (OutFile == 0) { + OutFile = MakeFilename (InFile, ".dis"); + } + + /* Load the input file */ + LoadCode (InFile, 0xE000); /* ### */ + + /* Open the output file */ + OpenOutput (OutFile); + + /* Disassemble the code */ + Disassemble (); + + /* Close the output file */ + CloseOutput (); + + /* Done */ + return EXIT_SUCCESS; +} + + + diff --git a/src/da65/make/gcc.mak b/src/da65/make/gcc.mak new file mode 100644 index 000000000..d0502f70b --- /dev/null +++ b/src/da65/make/gcc.mak @@ -0,0 +1,56 @@ +# +# gcc Makefile for da65 +# + +# Library dir +COMMON = ../common + +CFLAGS = -g -O2 -Wall -I$(COMMON) +CC=gcc +LDFLAGS= + +OBJS = attrtab.o \ + code.o \ + cpu.o \ + error.o \ + global.o \ + handler.o \ + main.o \ + opctable.o \ + output.o + +LIBS = $(COMMON)/common.a + + +EXECS = da65 + +.PHONY: all +ifeq (.depend,$(wildcard .depend)) +all : $(EXECS) +include .depend +else +all: depend + @$(MAKE) -f make/gcc.mak all +endif + + + +da65: $(OBJS) $(LIBS) + $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) + +clean: + rm -f *~ core *.map + +zap: clean + rm -f *.o $(EXECS) .depend + + +# ------------------------------------------------------------------------------ +# Make the dependencies + +.PHONY: depend dep +depend dep: $(OBJS:.o=.c) + @echo "Creating dependency information" + $(CC) -I$(COMMON) -MM $^ > .depend + + diff --git a/src/da65/opctable.c b/src/da65/opctable.c new file mode 100644 index 000000000..da72b672a --- /dev/null +++ b/src/da65/opctable.c @@ -0,0 +1,1843 @@ +/*****************************************************************************/ +/* */ +/* opctable.c */ +/* */ +/* Disassembler opcode description table */ +/* */ +/* */ +/* */ +/* (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. */ +/* */ +/*****************************************************************************/ + + + +#include "handler.h" +#include "opctable.h" + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +const OpcDesc OpcTable[256] = { + { /* $00 */ + "brk", + 2, + 0, + cpuAll, + OH_Implicit + }, + { /* $01 */ + "ora", + 2, + lfUseLabel, + cpuAll, + OH_DirectXIndirect + }, + { /* $02 */ + "cop", + 2, + 0, + cpu65816, + OH_Implicit + }, + { /* $03 */ + "ora", + 2, + 0, + cpu65816, + OH_StackRelative + }, + { /* $04 */ + "tsb", + 2, + lfUseLabel, + cpu65816, + OH_Direct + }, + { /* $05 */ + "ora", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $06 */ + "asl", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $07 */ + "ora", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirectLong + }, + { /* $08 */ + "php", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $09 */ + "ora", + 2, + 0, + cpuAll, + OH_Immidiate + }, + { /* $0a */ + "asl", + 1, + 0, + cpuAll, + OH_Accumulator + }, + { /* $0b */ + "phd", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $0c */ + "tsb", + 3, + lfUseLabel, + cpu65816, + OH_Absolute + }, + { /* $0d */ + "ora", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $0e */ + "asl", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $0f */ + "ora", + 4, + lfUseLabel, + cpu65816, + OH_AbsoluteLong + }, + { /* $10 */ + "bpl", + 2, + lfLabel, + cpuAll, + OH_Relative + }, + { /* $11 */ + "ora", + 2, + lfUseLabel, + cpuAll, + OH_DirectIndirectY + }, + { /* $12 */ + "ora", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirect + }, + { /* $13 */ + "ora", + 2, + 0, + cpu65816, + OH_StackRelativeIndirectY + }, + { /* $14 */ + "trb", + 2, + lfUseLabel, + cpu65816, + OH_Direct + }, + { /* $15 */ + "ora", + 2, + lfUseLabel, + cpuAll, + OH_DirectX + }, + { /* $16 */ + "asl", + 2, + lfUseLabel, + cpuAll, + OH_DirectX + }, + { /* $17 */ + "ora", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirectLongY + }, + { /* $18 */ + "clc", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $19 */ + "ora", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteY + }, + { /* $1a */ + "inc", + 1, + 0, + cpu65816, + OH_Accumulator + }, + { /* $1b */ + "tcs", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $1c */ + "trb", + 3, + lfUseLabel, + cpu65816, + OH_Absolute + }, + { /* $1d */ + "ora", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteX + }, + { /* $1e */ + "asl", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteX + }, + { /* $1f */ + "ora", + 4, + lfUseLabel, + cpu65816, + OH_AbsoluteLongX + }, + { /* $20 */ + "jsr", + 3, + lfLabel, + cpuAll, + OH_Absolute + }, + { /* $21 */ + "and", + 2, + lfUseLabel, + cpuAll, + OH_DirectXIndirect + }, + { /* $22 */ + "jsl", + 3, + lfLabel, + cpu65816, + OH_AbsoluteLong + }, + { /* $23 */ + "and", + 2, + 0, + cpu65816, + OH_StackRelative + }, + { /* $24 */ + "bit", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $25 */ + "and", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $26 */ + "rol", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $27 */ + "and", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirectLong + }, + { /* $28 */ + "plp", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $29 */ + "and", + 2, + 0, + cpuAll, + OH_Immidiate + }, + { /* $2a */ + "rol", + 1, + 0, + cpuAll, + OH_Accumulator + }, + { /* $2b */ + "pld", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $2c */ + "bit", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $2d */ + "and", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $2e */ + "rol", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $2f */ + "and", + 4, + lfUseLabel, + cpu65816, + OH_AbsoluteLong + }, + { /* $30 */ + "bmi", + 2, + lfLabel, + cpuAll, + OH_Relative + }, + { /* $31 */ + "and", + 2, + lfUseLabel, + cpuAll, + OH_DirectIndirectY + }, + { /* $32 */ + "and", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirect + }, + { /* $33 */ + "and", + 2, + 0, + cpu65816, + OH_StackRelativeIndirectY + }, + { /* $34 */ + "bit", + 2, + lfUseLabel, + cpu65816, + OH_DirectX + }, + { /* $35 */ + "and", + 2, + lfUseLabel, + cpuAll, + OH_DirectX + }, + { /* $36 */ + "rol", + 2, + lfUseLabel, + cpuAll, + OH_DirectX + }, + { /* $37 */ + "and", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirectLongY + }, + { /* $38 */ + "sec", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $39 */ + "and", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteY + }, + { /* $3a */ + "dec", + 1, + 0, + cpu65816, + OH_Accumulator + }, + { /* $3b */ + "tsc", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $3c */ + "bit", + 3, + lfUseLabel, + cpu65816, + OH_AbsoluteX + }, + { /* $3d */ + "and", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteX + }, + { /* $3e */ + "rol", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteX + }, + { /* $3f */ + "and", + 4, + lfUseLabel, + cpu65816, + OH_AbsoluteLongX + }, + { /* $40 */ + "rti", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $41 */ + "eor", + 2, + lfUseLabel, + cpuAll, + OH_DirectXIndirect + }, + { /* $42 */ + "wdm", + 2, + 0, + cpu65816, + OH_Implicit + }, + { /* $43 */ + "eor", + 2, + 0, + cpu65816, + OH_StackRelative + }, + { /* $44 */ + "mvp", + 3, + 0, + cpu65816, + OH_BlockMove + }, + { /* $45 */ + "eor", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $46 */ + "lsr", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $47 */ + "eor", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirectLong + }, + { /* $48 */ + "pha", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $49 */ + "eor", + 2, + 0, + cpuAll, + OH_Immidiate + }, + { /* $4a */ + "lsr", + 1, + 0, + cpuAll, + OH_Accumulator + }, + { /* $4b */ + "phk", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $4c */ + "jmp", + 3, + lfLabel, + cpuAll, + OH_JmpAbsolute + }, + { /* $4d */ + "eor", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $4e */ + "lsr", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $4f */ + "eor", + 4, + lfUseLabel, + cpu65816, + OH_AbsoluteLong + }, + { /* $50 */ + "bvc", + 2, + lfLabel, + cpuAll, + OH_Relative + }, + { /* $51 */ + "eor", + 2, + lfUseLabel, + cpuAll, + OH_DirectIndirectY + }, + { /* $52 */ + "eor", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirect + }, + { /* $53 */ + "eor", + 2, + 0, + cpu65816, + OH_StackRelativeIndirectY + }, + { /* $54 */ + "mvn", + 3, + 0, + cpu65816, + OH_BlockMove + }, + { /* $55 */ + "eor", + 2, + lfUseLabel, + cpuAll, + OH_DirectX + }, + { /* $56 */ + "lsr", + 2, + lfUseLabel, + cpuAll, + OH_DirectX + }, + { /* $57 */ + "eor", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirectLongY + }, + { /* $58 */ + "cli", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $59 */ + "eor", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteY + }, + { /* $5a */ + "phy", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $5b */ + "tcd", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $5c */ + "jml", + 4, + lfLabel, + cpu65816, + OH_AbsoluteLong + }, + { /* $5d */ + "eor", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteX + }, + { /* $5e */ + "lsr", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteX + }, + { /* $5f */ + "eor", + 4, + lfUseLabel, + cpu65816, + OH_AbsoluteLongX + }, + { /* $60 */ + "rts", + 1, + 0, + cpuAll, + OH_Rts + }, + { /* $61 */ + "adc", + 2, + lfUseLabel, + cpuAll, + OH_DirectXIndirect + }, + { /* $62 */ + "per", + 3, + lfLabel, + cpu65816, + OH_RelativeLong + }, + { /* $63 */ + "adc", + 2, + 0, + cpu65816, + OH_StackRelative + }, + { /* $64 */ + "stz", + 2, + lfUseLabel, + cpu65816, + OH_Direct + }, + { /* $65 */ + "adc", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $66 */ + "ror", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $67 */ + "adc", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirectLong + }, + { /* $68 */ + "pla", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $69 */ + "adc", + 2, + 0, + cpuAll, + OH_Immidiate + }, + { /* $6a */ + "ror", + 1, + 0, + cpuAll, + OH_Accumulator + }, + { /* $6b */ + "rtl", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $6c */ + "jmp", + 3, + lfLabel, + cpuAll, + OH_AbsoluteIndirect + }, + { /* $6d */ + "adc", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $6e */ + "ror", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $6f */ + "adc", + 4, + lfUseLabel, + cpu65816, + OH_AbsoluteLong + }, + { /* $70 */ + "bvs", + 2, + lfLabel, + cpuAll, + OH_Relative + }, + { /* $71 */ + "adc", + 2, + lfUseLabel, + cpuAll, + OH_DirectIndirectY + }, + { /* $72 */ + "adc", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirect + }, + { /* $73 */ + "adc", + 2, + 0, + cpu65816, + OH_StackRelativeIndirectY + }, + { /* $74 */ + "stz", + 2, + lfUseLabel, + cpu65816, + OH_DirectX + }, + { /* $75 */ + "adc", + 2, + lfUseLabel, + cpuAll, + OH_DirectX + }, + { /* $76 */ + "ror", + 2, + lfUseLabel, + cpuAll, + OH_DirectX + }, + { /* $77 */ + "adc", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirectLongY + }, + { /* $78 */ + "sei", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $79 */ + "adc", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteY + }, + { /* $7a */ + "ply", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $7b */ + "tdc", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $7c */ + "jmp", + 3, + lfLabel, + cpu65816, + OH_AbsoluteXIndirect + }, + { /* $7d */ + "adc", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteX + }, + { /* $7e */ + "ror", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteX + }, + { /* $7f */ + "adc", + 4, + lfUseLabel, + cpu65816, + OH_AbsoluteLongX + }, + { /* $80 */ + "bra", + 2, + lfLabel, + cpu65816, + OH_Relative + }, + { /* $81 */ + "sta", + 2, + lfUseLabel, + cpuAll, + OH_DirectXIndirect + }, + { /* $82 */ + "brl", + 3, + lfLabel, + cpu65816, + OH_RelativeLong + }, + { /* $83 */ + "sta", + 2, + 0, + cpu65816, + OH_StackRelative + }, + { /* $84 */ + "sty", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $85 */ + "sta", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $86 */ + "stx", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $87 */ + "sta", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirectLong + }, + { /* $88 */ + "dey", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $89 */ + "bit", + 2, + 0, + cpu65816, + OH_Immidiate + }, + { /* $8a */ + "txa", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $8b */ + "phb", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $8c */ + "sty", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $8d */ + "sta", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $8e */ + "stx", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $8f */ + "sta", + 4, + lfUseLabel, + cpu65816, + OH_AbsoluteLong + }, + { /* $90 */ + "bcc", + 2, + lfLabel, + cpuAll, + OH_Relative + }, + { /* $91 */ + "sta", + 2, + lfUseLabel, + cpuAll, + OH_DirectIndirectY + }, + { /* $92 */ + "sta", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirect + }, + { /* $93 */ + "sta", + 2, + 0, + cpu65816, + OH_StackRelativeIndirectY + }, + { /* $94 */ + "sty", + 2, + lfUseLabel, + cpuAll, + OH_DirectX + }, + { /* $95 */ + "sta", + 2, + lfUseLabel, + cpuAll, + OH_DirectX + }, + { /* $96 */ + "stx", + 2, + lfUseLabel, + cpuAll, + OH_DirectY + }, + { /* $97 */ + "sta", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirectLongY + }, + { /* $98 */ + "tya", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $99 */ + "sta", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteY + }, + { /* $9a */ + "txs", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $9b */ + "txy", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $9c */ + "stz", + 3, + lfUseLabel, + cpu65816, + OH_Absolute + }, + { /* $9d */ + "sta", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteX + }, + { /* $9e */ + "stz", + 3, + lfUseLabel, + cpu65816, + OH_AbsoluteX + }, + { /* $9f */ + "sta", + 4, + lfUseLabel, + cpu65816, + OH_AbsoluteLongX + }, + { /* $a0 */ + "ldy", + 2, + 0, + cpuAll, + OH_Immidiate + }, + { /* $a1 */ + "lda", + 2, + lfUseLabel, + cpuAll, + OH_DirectXIndirect + }, + { /* $a2 */ + "ldx", + 2, + 0, + cpuAll, + OH_Immidiate + }, + { /* $a3 */ + "lda", + 2, + 0, + cpu65816, + OH_StackRelative + }, + { /* $a4 */ + "ldy", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $a5 */ + "lda", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $a6 */ + "ldx", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $a7 */ + "lda", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirectLong + }, + { /* $a8 */ + "tay", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $a9 */ + "lda", + 2, + 0, + cpuAll, + OH_Immidiate + }, + { /* $aa */ + "tax", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $ab */ + "plb", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $ac */ + "ldy", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $ad */ + "lda", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $ae */ + "ldx", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $af */ + "lda", + 4, + lfUseLabel, + cpu65816, + OH_AbsoluteLong + }, + { /* $b0 */ + "bcs", + 2, + lfLabel, + cpuAll, + OH_Relative + }, + { /* $b1 */ + "lda", + 2, + lfUseLabel, + cpuAll, + OH_DirectIndirectY + }, + { /* $b2 */ + "lda", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirect + }, + { /* $b3 */ + "lda", + 2, + 0, + cpu65816, + OH_StackRelativeIndirectY + }, + { /* $b4 */ + "ldy", + 2, + lfUseLabel, + cpuAll, + OH_DirectX + }, + { /* $b5 */ + "lda", + 2, + lfUseLabel, + cpuAll, + OH_DirectX + }, + { /* $b6 */ + "ldx", + 2, + lfUseLabel, + cpuAll, + OH_DirectY + }, + { /* $b7 */ + "lda", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirectLongY + }, + { /* $b8 */ + "clv", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $b9 */ + "lda", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteY + }, + { /* $ba */ + "tsx", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $bb */ + "tyx", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $bc */ + "ldy", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteX + }, + { /* $bd */ + "lda", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteX + }, + { /* $be */ + "ldx", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteY + }, + { /* $bf */ + "lda", + 4, + lfUseLabel, + cpu65816, + OH_AbsoluteLongX + }, + { /* $c0 */ + "cpy", + 2, + 0, + cpuAll, + OH_Immidiate + }, + { /* $c1 */ + "cmp", + 2, + lfUseLabel, + cpuAll, + OH_DirectXIndirect + }, + { /* $c2 */ + "rep", + 2, + 0, + cpu65816, + OH_Immidiate + }, + { /* $c3 */ + "cmp", + 2, + 0, + cpu65816, + OH_StackRelative + }, + { /* $c4 */ + "cpy", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $c5 */ + "cmp", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $c6 */ + "dec", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $c7 */ + "cmp", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirectLong + }, + { /* $c8 */ + "iny", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $c9 */ + "cmp", + 2, + 0, + cpuAll, + OH_Immidiate + }, + { /* $ca */ + "dex", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $cb */ + "wai", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $cc */ + "cpy", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $cd */ + "cmp", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $ce */ + "dec", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $cf */ + "cmp", + 4, + lfUseLabel, + cpu65816, + OH_AbsoluteLong + }, + { /* $d0 */ + "bne", + 2, + lfLabel, + cpuAll, + OH_Relative + }, + { /* $d1 */ + "cmp", + 2, + lfUseLabel, + cpuAll, + OH_DirectXIndirect + }, + { /* $d2 */ + "cmp", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirect + }, + { /* $d3 */ + "cmp", + 2, + 0, + cpu65816, + OH_StackRelativeIndirectY + }, + { /* $d4 */ + "pei", + 2, + lfUseLabel, + cpu65816, + OH_Direct + }, + { /* $d5 */ + "cmp", + 2, + lfUseLabel, + cpuAll, + OH_DirectX + }, + { /* $d6 */ + "dec", + 2, + lfUseLabel, + cpuAll, + OH_DirectX + }, + { /* $d7 */ + "cmp", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirectLongY + }, + { /* $d8 */ + "cld", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $d9 */ + "cmp", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteY + }, + { /* $da */ + "phx", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $db */ + "stp", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $dc */ + "jml", + 3, + lfLabel, + cpu65816, + OH_AbsoluteIndirect + }, + { /* $dd */ + "cmp", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteX + }, + { /* $de */ + "dec", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteX + }, + { /* $df */ + "cmp", + 4, + lfUseLabel, + cpu65816, + OH_AbsoluteLongX + }, + { /* $e0 */ + "cpx", + 2, + 0, + cpuAll, + OH_Immidiate + }, + { /* $e1 */ + "sbc", + 2, + lfUseLabel, + cpuAll, + OH_DirectXIndirect + }, + { /* $e2 */ + "sep", + 2, + 0, + cpu65816, + OH_Immidiate + }, + { /* $e3 */ + "sbc", + 2, + 0, + cpu65816, + OH_StackRelative + }, + { /* $e4 */ + "cpx", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $e5 */ + "sbc", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $e6 */ + "inc", + 2, + lfUseLabel, + cpuAll, + OH_Direct + }, + { /* $e7 */ + "sbc", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirectLong + }, + { /* $e8 */ + "inx", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $e9 */ + "sbc", + 2, + 0, + cpuAll, + OH_Immidiate + }, + { /* $ea */ + "nop", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $eb */ + "xba", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $ec */ + "cpx", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $ed */ + "sbc", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $ee */ + "inc", + 3, + lfUseLabel, + cpuAll, + OH_Absolute + }, + { /* $ef */ + "sbc", + 4, + lfUseLabel, + cpu65816, + OH_AbsoluteLong + }, + { /* $f0 */ + "beq", + 2, + lfLabel, + cpuAll, + OH_Relative + }, + { /* $f1 */ + "sbc", + 2, + lfUseLabel, + cpuAll, + OH_DirectIndirectY + }, + { /* $f2 */ + "sbc", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirect + }, + { /* $f3 */ + "sbc", + 2, + 0, + cpu65816, + OH_StackRelativeIndirectY + }, + { /* $f4 */ + "pea", + 3, + lfUseLabel, + cpu65816, + OH_Absolute + }, + { /* $f5 */ + "sbc", + 2, + lfUseLabel, + cpuAll, + OH_DirectX + }, + { /* $f6 */ + "inc", + 2, + lfUseLabel, + cpuAll, + OH_DirectX + }, + { /* $f7 */ + "sbc", + 2, + lfUseLabel, + cpu65816, + OH_DirectIndirectLongY + }, + { /* $f8 */ + "sed", + 1, + 0, + cpuAll, + OH_Implicit + }, + { /* $f9 */ + "sbc", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteY + }, + { /* $fa */ + "plx", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $fb */ + "xce", + 1, + 0, + cpu65816, + OH_Implicit + }, + { /* $fc */ + "jsr", + 3, + lfLabel, + cpu65816, + OH_AbsoluteXIndirect + }, + { /* $fd */ + "sbc", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteX + }, + { /* $fe */ + "inc", + 3, + lfUseLabel, + cpuAll, + OH_AbsoluteX + }, + { /* $ff */ + "sbc", + 4, + lfUseLabel, + cpu65816, + OH_AbsoluteLongX + }, +}; + + + diff --git a/src/da65/opctable.h b/src/da65/opctable.h new file mode 100644 index 000000000..480fe8854 --- /dev/null +++ b/src/da65/opctable.h @@ -0,0 +1,87 @@ +/*****************************************************************************/ +/* */ +/* opctable.h */ +/* */ +/* Disassembler opcode description table */ +/* */ +/* */ +/* */ +/* (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 OPCTABLE_H +#define OPCTABLE_H + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +/* Constants for LabelFlag */ +enum { + lfNoLabel = 0x00, /* Don't use a label */ + lfGenLabel = 0x01, /* Generate a label */ + lfUseLabel = 0x02, /* Use a label if there is one */ + lfLabel = lfUseLabel|lfGenLabel /* Generate and use a label */ +}; + +/* Constants for the CPU type */ +enum { + cpu6502 = 0x01, + cpu65C02 = 0x02, + cpu65816 = 0x04, + cpuAll = 0x07, +}; + +/* Forward/typedef for struct OpcDesc */ +typedef struct OpcDesc OpcDesc; + +/* Type of pointer to a function that handles opcode output */ +typedef void (*OpcHandler) (const OpcDesc*); + +/* Description for one opcode */ +struct OpcDesc { + char Mnemo [4]; /* Mnemonic */ + unsigned char Size; /* Size of this command */ + unsigned char LabelFlag; /* Generate/use label? */ + unsigned char CPU; /* Available for which CPU? */ + OpcHandler Handler; /* Handler routine */ +}; + +/* Descriptions for all opcodes */ +extern const OpcDesc OpcTable[256]; + + + +/* End of opctable.h */ +#endif + + + diff --git a/src/da65/output.c b/src/da65/output.c new file mode 100644 index 000000000..2f4514e19 --- /dev/null +++ b/src/da65/output.c @@ -0,0 +1,155 @@ +/*****************************************************************************/ +/* */ +/* output.c */ +/* */ +/* Disassembler 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. */ +/* */ +/*****************************************************************************/ + + + +#include +#include +#include +#include + +/* da65 */ +#include "code.h" +#include "error.h" +#include "global.h" +#include "output.h" + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +static FILE* F = 0; /* Output stream */ +static unsigned Col = 1; /* Current column */ + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void OpenOutput (const char* Name) +/* Open the given file for output */ +{ + /* Open the output file */ + F = fopen (Name, "w"); + if (F == 0) { + Error ("Cannot open `%s': %s", Name, strerror (errno)); + } +} + + + +void CloseOutput (void) +/* Close the output file */ +{ + if (fclose (F) != 0) { + Error ("Error closing output file: %s", strerror (errno)); + } +} + + + +void Output (const char* Format, ...) +/* Write to the output file */ +{ + if (Pass > 1) { + va_list ap; + va_start (ap, Format); + Col += vfprintf (F, Format, ap); + va_end (ap); + } +} + + + +void Indent (unsigned N) +/* Make sure the current line column is at position N (zero based) */ +{ + if (Pass > 1) { + while (Col < N) { + fputc (' ', F); + ++Col; + } + } +} + + + +void LineFeed (void) +/* Add a linefeed to the output file */ +{ + if (Pass > 1) { + fputc ('\n', F); + Col = 1; + } +} + + + +void DefLabel (const char* Name) +/* Define a label with the given name */ +{ + Output ("%s:", Name); + LineFeed (); +} + + + +void OneDataByte (void) +/* Output a .byte line with the current code byte */ +{ + if (Pass > 1) { + Indent (MIndent); + Output (".byte"); + Indent (AIndent); + Output ("$%02X", GetCodeByte()); + LineFeed (); + } +} + + + +void SeparatorLine (void) +/* Print a separator line */ +{ + Output ("; -------------------------------------------------------------------------"); + LineFeed (); +} + + + diff --git a/src/da65/output.h b/src/da65/output.h new file mode 100644 index 000000000..e6e67f0f8 --- /dev/null +++ b/src/da65/output.h @@ -0,0 +1,83 @@ +/*****************************************************************************/ +/* */ +/* output.h */ +/* */ +/* Disassembler 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 OUTPUT_H +#define OUTPUT_H + + + +/* common */ +#include "attrib.h" + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void OpenOutput (const char* Name); +/* Open the given file for output */ + +void CloseOutput (void); +/* Close the output file */ + +void Output (const char* Format, ...) attribute ((format(printf, 1, 2))); +/* Write to the output file */ + +void Indent (unsigned N); +/* Make sure the current line column is at position N (zero based) */ + +void LineFeed (void); +/* Add a linefeed to the output file */ + +void DefLabel (const char* Name); +/* Define a label with the given name */ + +void OneDataByte (void); +/* Output a .byte line with the current code byte */ + +void SeparatorLine (void); +/* Print a separator line */ + + + +/* End of output.h */ +#endif + + + +