2000-05-28 13:40:48 +00:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* */
|
2003-05-01 23:24:20 +00:00
|
|
|
|
/* instr.h */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* */
|
|
|
|
|
/* Instruction encoding for the ca65 macroassembler */
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
2004-10-03 21:26:00 +00:00
|
|
|
|
/* (C) 1998-2004 Ullrich von Bassewitz */
|
2003-05-01 23:24:20 +00:00
|
|
|
|
/* R<>merstrasse 52 */
|
|
|
|
|
/* D-70794 Filderstadt */
|
|
|
|
|
/* EMail: uz@cc65.org */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
/* 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 INSTR_H
|
|
|
|
|
#define INSTR_H
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-05-01 23:24:20 +00:00
|
|
|
|
/* common */
|
|
|
|
|
#include "cpu.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/*****************************************************************************/
|
2004-10-03 21:26:00 +00:00
|
|
|
|
/* Data for 6502 and successors */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Constants for the addressing mode. If an opcode is available in zero page
|
|
|
|
|
* and absolut adressing mode, both bits are set. When checking for valid
|
|
|
|
|
* modes, the zeropage bit is checked first. Similar, the implicit bit is set
|
|
|
|
|
* on accu adressing modes, so the 'A' for accu adressing is not needed (but
|
|
|
|
|
* may be specified).
|
|
|
|
|
* When assembling for the 6502 or 65C02, all addressing modes that are not
|
|
|
|
|
* available on these CPUs are removed before doing any checks.
|
|
|
|
|
*/
|
2005-08-26 12:46:44 +00:00
|
|
|
|
#define AM65_IMPLICIT 0x00000003UL
|
|
|
|
|
#define AM65_ACCU 0x00000002UL
|
2004-10-03 21:26:00 +00:00
|
|
|
|
#define AM65_DIR 0x00000004UL
|
|
|
|
|
#define AM65_ABS 0x00000008UL
|
|
|
|
|
#define AM65_ABS_LONG 0x00000010UL
|
|
|
|
|
#define AM65_DIR_X 0x00000020UL
|
|
|
|
|
#define AM65_ABS_X 0x00000040UL
|
|
|
|
|
#define AM65_ABS_LONG_X 0x00000080UL
|
2005-08-26 12:46:44 +00:00
|
|
|
|
#define AM65_DIR_Y 0x00000100UL
|
|
|
|
|
#define AM65_ABS_Y 0x00000200UL
|
|
|
|
|
#define AM65_DIR_IND 0x00000400UL
|
|
|
|
|
#define AM65_ABS_IND 0x00000800UL
|
|
|
|
|
#define AM65_DIR_IND_LONG 0x00001000UL
|
|
|
|
|
#define AM65_DIR_IND_Y 0x00002000UL
|
|
|
|
|
#define AM65_DIR_IND_LONG_Y 0x00004000UL
|
|
|
|
|
#define AM65_DIR_X_IND 0x00008000UL
|
|
|
|
|
#define AM65_ABS_X_IND 0x00010000UL
|
|
|
|
|
#define AM65_REL 0x00020000UL
|
|
|
|
|
#define AM65_REL_LONG 0x00040000UL
|
|
|
|
|
#define AM65_STACK_REL 0x00080000UL
|
|
|
|
|
#define AM65_STACK_REL_IND_Y 0x00100000UL
|
2004-10-03 21:26:00 +00:00
|
|
|
|
#define AM65_IMM_ACCU 0x00200000UL
|
|
|
|
|
#define AM65_IMM_INDEX 0x00400000UL
|
2005-08-26 12:46:44 +00:00
|
|
|
|
#define AM65_IMM_IMPLICIT 0x00800000UL
|
|
|
|
|
#define AM65_IMM (AM65_IMM_ACCU | AM65_IMM_INDEX | AM65_IMM_IMPLICIT)
|
|
|
|
|
#define AM65_BLOCKMOVE 0x01000000UL
|
2005-09-01 19:40:34 +00:00
|
|
|
|
#define AM65_BLOCKXFER 0x02000000UL
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
/* Bitmask for all ZP operations that have correspondent ABS ops */
|
2004-10-03 21:26:00 +00:00
|
|
|
|
#define AM65_SET_ZP (AM65_DIR | AM65_DIR_X | AM65_DIR_Y | AM65_DIR_IND | AM65_DIR_X_IND)
|
2003-12-12 12:59:10 +00:00
|
|
|
|
|
|
|
|
|
/* Bitmask for all ABS operations that have correspondent FAR ops */
|
2004-10-03 21:26:00 +00:00
|
|
|
|
#define AM65_SET_ABS (AM65_ABS | AM65_ABS_X)
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
/* Bit numbers and count */
|
2004-10-03 21:26:00 +00:00
|
|
|
|
#define AM65I_IMM_ACCU 21
|
|
|
|
|
#define AM65I_IMM_INDEX 22
|
2005-09-01 19:40:34 +00:00
|
|
|
|
#define AM65I_COUNT 26
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Description for one instruction */
|
2003-05-13 19:10:32 +00:00
|
|
|
|
typedef struct InsDesc InsDesc;
|
|
|
|
|
struct InsDesc {
|
2003-08-07 11:12:39 +00:00
|
|
|
|
char Mnemonic[5];
|
2005-09-01 19:40:34 +00:00
|
|
|
|
unsigned long AddrMode; /* Valid adressing modes */
|
|
|
|
|
unsigned char BaseCode; /* Base opcode */
|
|
|
|
|
unsigned char ExtCode; /* Number of ext code table */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
void (*Emit) (const InsDesc*);/* Handler function */
|
|
|
|
|
};
|
|
|
|
|
|
2005-09-01 19:40:34 +00:00
|
|
|
|
/* An instruction table */
|
2003-05-13 19:10:32 +00:00
|
|
|
|
typedef struct InsTable InsTable;
|
|
|
|
|
struct InsTable {
|
2005-09-01 19:40:34 +00:00
|
|
|
|
unsigned Count; /* Number of intstructions */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
InsDesc Ins[1]; /* Varying length */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* The instruction table for the currently active CPU */
|
|
|
|
|
extern const InsTable* InsTab;
|
|
|
|
|
|
|
|
|
|
/* Table that encodes the additional bytes for each instruction */
|
2004-10-03 21:26:00 +00:00
|
|
|
|
extern unsigned char ExtBytes[AM65I_COUNT];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Data for the SWEET16 pseudo CPU */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* SWEET16 addressing modes */
|
|
|
|
|
#define AMSW16_IMP 0x0001 /* Implicit */
|
|
|
|
|
#define AMSW16_BRA 0x0002 /* A branch */
|
|
|
|
|
#define AMSW16_IMM 0x0004 /* Immediate */
|
|
|
|
|
#define AMSW16_IND 0x0008 /* Indirect */
|
|
|
|
|
#define AMSW16_REG 0x0010 /* Register */
|
|
|
|
|
|
|
|
|
|
#define AMSW16I_COUNT 5 /* Number of addressing modes */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-10-03 21:26:00 +00:00
|
|
|
|
/* Code */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-05-01 23:24:20 +00:00
|
|
|
|
void SetCPU (cpu_t NewCPU);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* Set a new CPU */
|
|
|
|
|
|
2003-05-01 23:24:20 +00:00
|
|
|
|
cpu_t GetCPU (void);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* Return the current CPU */
|
|
|
|
|
|
|
|
|
|
int FindInstruction (const char* Ident);
|
|
|
|
|
/* Check if Ident is a valid mnemonic. If so, return the index in the
|
|
|
|
|
* instruction table. If not, return -1.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void HandleInstruction (unsigned Index);
|
|
|
|
|
/* Handle the mnemonic with the given index */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* End of instr.h */
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|