Added 65C02 instructions
git-svn-id: svn://svn.cc65.org/cc65/trunk@2249 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -66,6 +66,7 @@
|
|||||||
static void PutPCRel8 (const InsDesc* Ins);
|
static void PutPCRel8 (const InsDesc* Ins);
|
||||||
static void PutPCRel16 (const InsDesc* Ins);
|
static void PutPCRel16 (const InsDesc* Ins);
|
||||||
static void PutBlockMove (const InsDesc* Ins);
|
static void PutBlockMove (const InsDesc* Ins);
|
||||||
|
static void PutBitBranch (const InsDesc* Ins);
|
||||||
static void PutREP (const InsDesc* Ins);
|
static void PutREP (const InsDesc* Ins);
|
||||||
static void PutSEP (const InsDesc* Ins);
|
static void PutSEP (const InsDesc* Ins);
|
||||||
static void PutJmp (const InsDesc* Ins);
|
static void PutJmp (const InsDesc* Ins);
|
||||||
@@ -218,7 +219,7 @@ static const struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Instruction table for the 65C02 */
|
/* Instruction table for the 65C02 */
|
||||||
#define INS_COUNT_65C02 66
|
#define INS_COUNT_65C02 98
|
||||||
static const struct {
|
static const struct {
|
||||||
unsigned Count;
|
unsigned Count;
|
||||||
InsDesc Ins[INS_COUNT_65C02];
|
InsDesc Ins[INS_COUNT_65C02];
|
||||||
@@ -228,6 +229,22 @@ static const struct {
|
|||||||
{ "ADC", 0x080A66C, 0x60, 0, PutAll },
|
{ "ADC", 0x080A66C, 0x60, 0, PutAll },
|
||||||
{ "AND", 0x080A66C, 0x20, 0, PutAll },
|
{ "AND", 0x080A66C, 0x20, 0, PutAll },
|
||||||
{ "ASL", 0x000006e, 0x02, 1, PutAll },
|
{ "ASL", 0x000006e, 0x02, 1, PutAll },
|
||||||
|
{ "BBR0", 0x0000000, 0x0F, 0, PutBitBranch },
|
||||||
|
{ "BBR1", 0x0000000, 0x1F, 0, PutBitBranch },
|
||||||
|
{ "BBR2", 0x0000000, 0x2F, 0, PutBitBranch },
|
||||||
|
{ "BBR3", 0x0000000, 0x3F, 0, PutBitBranch },
|
||||||
|
{ "BBR4", 0x0000000, 0x4F, 0, PutBitBranch },
|
||||||
|
{ "BBR5", 0x0000000, 0x5F, 0, PutBitBranch },
|
||||||
|
{ "BBR6", 0x0000000, 0x6F, 0, PutBitBranch },
|
||||||
|
{ "BBR7", 0x0000000, 0x7F, 0, PutBitBranch },
|
||||||
|
{ "BBS0", 0x0000000, 0x8F, 0, PutBitBranch },
|
||||||
|
{ "BBS1", 0x0000000, 0x9F, 0, PutBitBranch },
|
||||||
|
{ "BBS2", 0x0000000, 0xAF, 0, PutBitBranch },
|
||||||
|
{ "BBS3", 0x0000000, 0xBF, 0, PutBitBranch },
|
||||||
|
{ "BBS4", 0x0000000, 0xCF, 0, PutBitBranch },
|
||||||
|
{ "BBS5", 0x0000000, 0xDF, 0, PutBitBranch },
|
||||||
|
{ "BBS6", 0x0000000, 0xEF, 0, PutBitBranch },
|
||||||
|
{ "BBS7", 0x0000000, 0xFF, 0, PutBitBranch },
|
||||||
{ "BCC", 0x0020000, 0x90, 0, PutPCRel8 },
|
{ "BCC", 0x0020000, 0x90, 0, PutPCRel8 },
|
||||||
{ "BCS", 0x0020000, 0xb0, 0, PutPCRel8 },
|
{ "BCS", 0x0020000, 0xb0, 0, PutPCRel8 },
|
||||||
{ "BEQ", 0x0020000, 0xf0, 0, PutPCRel8 },
|
{ "BEQ", 0x0020000, 0xf0, 0, PutPCRel8 },
|
||||||
@@ -271,6 +288,14 @@ static const struct {
|
|||||||
{ "PLP", 0x0000001, 0x28, 0, PutAll },
|
{ "PLP", 0x0000001, 0x28, 0, PutAll },
|
||||||
{ "PLX", 0x0000001, 0xfa, 0, PutAll },
|
{ "PLX", 0x0000001, 0xfa, 0, PutAll },
|
||||||
{ "PLY", 0x0000001, 0x7a, 0, PutAll },
|
{ "PLY", 0x0000001, 0x7a, 0, PutAll },
|
||||||
|
{ "RMB0", 0x0000004, 0x07, 1, PutAll },
|
||||||
|
{ "RMB1", 0x0000004, 0x17, 1, PutAll },
|
||||||
|
{ "RMB2", 0x0000004, 0x27, 1, PutAll },
|
||||||
|
{ "RMB3", 0x0000004, 0x37, 1, PutAll },
|
||||||
|
{ "RMB4", 0x0000004, 0x47, 1, PutAll },
|
||||||
|
{ "RMB5", 0x0000004, 0x57, 1, PutAll },
|
||||||
|
{ "RMB6", 0x0000004, 0x67, 1, PutAll },
|
||||||
|
{ "RMB7", 0x0000004, 0x77, 1, PutAll },
|
||||||
{ "ROL", 0x000006F, 0x22, 1, PutAll },
|
{ "ROL", 0x000006F, 0x22, 1, PutAll },
|
||||||
{ "ROR", 0x000006F, 0x62, 1, PutAll },
|
{ "ROR", 0x000006F, 0x62, 1, PutAll },
|
||||||
{ "RTI", 0x0000001, 0x40, 0, PutAll },
|
{ "RTI", 0x0000001, 0x40, 0, PutAll },
|
||||||
@@ -279,6 +304,14 @@ static const struct {
|
|||||||
{ "SEC", 0x0000001, 0x38, 0, PutAll },
|
{ "SEC", 0x0000001, 0x38, 0, PutAll },
|
||||||
{ "SED", 0x0000001, 0xf8, 0, PutAll },
|
{ "SED", 0x0000001, 0xf8, 0, PutAll },
|
||||||
{ "SEI", 0x0000001, 0x78, 0, PutAll },
|
{ "SEI", 0x0000001, 0x78, 0, PutAll },
|
||||||
|
{ "SMB0", 0x0000004, 0x87, 1, PutAll },
|
||||||
|
{ "SMB1", 0x0000004, 0x97, 1, PutAll },
|
||||||
|
{ "SMB2", 0x0000004, 0xA7, 1, PutAll },
|
||||||
|
{ "SMB3", 0x0000004, 0xB7, 1, PutAll },
|
||||||
|
{ "SMB4", 0x0000004, 0xC7, 1, PutAll },
|
||||||
|
{ "SMB5", 0x0000004, 0xD7, 1, PutAll },
|
||||||
|
{ "SMB6", 0x0000004, 0xE7, 1, PutAll },
|
||||||
|
{ "SMB7", 0x0000004, 0xF7, 1, PutAll },
|
||||||
{ "STA", 0x000A66C, 0x80, 0, PutAll },
|
{ "STA", 0x000A66C, 0x80, 0, PutAll },
|
||||||
{ "STX", 0x000010c, 0x82, 1, PutAll },
|
{ "STX", 0x000010c, 0x82, 1, PutAll },
|
||||||
{ "STY", 0x000002c, 0x80, 1, PutAll },
|
{ "STY", 0x000002c, 0x80, 1, PutAll },
|
||||||
@@ -688,6 +721,17 @@ static void PutBlockMove (const InsDesc* Ins)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void PutBitBranch (const InsDesc* Ins)
|
||||||
|
/* Handle 65C02 branch on bit condition */
|
||||||
|
{
|
||||||
|
Emit0 (Ins->BaseCode);
|
||||||
|
EmitByte (Expression ());
|
||||||
|
ConsumeComma ();
|
||||||
|
EmitSigned (GenBranchExpr (1), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void PutREP (const InsDesc* Ins)
|
static void PutREP (const InsDesc* Ins)
|
||||||
/* Emit a REP instruction, track register sizes */
|
/* Emit a REP instruction, track register sizes */
|
||||||
{
|
{
|
||||||
@@ -837,29 +881,26 @@ int FindInstruction (const char* Ident)
|
|||||||
* instruction table. If not, return -1.
|
* instruction table. If not, return -1.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
const InsDesc* I;
|
unsigned I;
|
||||||
char Key [sizeof (I->Mnemonic)];
|
const InsDesc* ID;
|
||||||
|
char Key[sizeof (ID->Mnemonic)];
|
||||||
/* Accept only strings with the right length */
|
|
||||||
if (strlen (Ident) != sizeof (I->Mnemonic)-1) {
|
|
||||||
/* Wrong length */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make a copy, and uppercase that copy */
|
/* Make a copy, and uppercase that copy */
|
||||||
Key [0] = toupper (Ident [0]);
|
I = 0;
|
||||||
Key [1] = toupper (Ident [1]);
|
while (Ident[I]) {
|
||||||
Key [2] = toupper (Ident [2]);
|
Key[I] = toupper ((unsigned char)Ident[I]);
|
||||||
Key [3] = '\0';
|
++I;
|
||||||
|
}
|
||||||
|
Key[I] = '\0';
|
||||||
|
|
||||||
/* Search for the key */
|
/* Search for the key */
|
||||||
I = bsearch (Key, InsTab->Ins, InsTab->Count, sizeof (InsDesc), CmpName);
|
ID = bsearch (Key, InsTab->Ins, InsTab->Count, sizeof (InsDesc), CmpName);
|
||||||
if (I == 0) {
|
if (ID == 0) {
|
||||||
/* Not found */
|
/* Not found */
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
/* Found, return the entry */
|
/* Found, return the entry */
|
||||||
return I - InsTab->Ins;
|
return ID - InsTab->Ins;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@
|
|||||||
/* Description for one instruction */
|
/* Description for one instruction */
|
||||||
typedef struct InsDesc InsDesc;
|
typedef struct InsDesc InsDesc;
|
||||||
struct InsDesc {
|
struct InsDesc {
|
||||||
char Mnemonic [4];
|
char Mnemonic [8];
|
||||||
unsigned long AddrMode; /* Valid adressing modes */
|
unsigned long AddrMode; /* Valid adressing modes */
|
||||||
unsigned char BaseCode; /* Base opcode */
|
unsigned char BaseCode; /* Base opcode */
|
||||||
unsigned char ExtCode; /* Number of ext code table */
|
unsigned char ExtCode; /* Number of ext code table */
|
||||||
|
|||||||
@@ -633,13 +633,20 @@ void Emit3b (unsigned char OPC, ExprNode* Expr, ExprNode* Bank)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void EmitSigned (ExprNode* Expr, unsigned Size)
|
||||||
|
/* Emit a signed expression with the given size */
|
||||||
|
{
|
||||||
|
Fragment* F = NewFragment (FRAG_SEXPR, Size);
|
||||||
|
F->V.Expr = Expr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void EmitPCRel (unsigned char OPC, ExprNode* Expr, unsigned Size)
|
void EmitPCRel (unsigned char OPC, ExprNode* Expr, unsigned Size)
|
||||||
/* Emit an opcode with a PC relative argument of one or two bytes */
|
/* Emit an opcode with a PC relative argument of one or two bytes */
|
||||||
{
|
{
|
||||||
Fragment* F;
|
|
||||||
Emit0 (OPC);
|
Emit0 (OPC);
|
||||||
F = NewFragment (FRAG_SEXPR, Size);
|
EmitSigned (Expr, Size);
|
||||||
F->V.Expr = Expr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -133,6 +133,9 @@ void Emit3 (unsigned char OPC, ExprNode* Expr);
|
|||||||
void Emit3b (unsigned char OPC, ExprNode* Expr, ExprNode* Bank);
|
void Emit3b (unsigned char OPC, ExprNode* Expr, ExprNode* Bank);
|
||||||
/* Emit an instruction with a three byte argument and separate bank */
|
/* Emit an instruction with a three byte argument and separate bank */
|
||||||
|
|
||||||
|
void EmitSigned (ExprNode* Expr, unsigned Size);
|
||||||
|
/* Emit a signed expression with the given size */
|
||||||
|
|
||||||
void EmitPCRel (unsigned char OPC, ExprNode* Expr, unsigned Size);
|
void EmitPCRel (unsigned char OPC, ExprNode* Expr, unsigned Size);
|
||||||
/* Emit an opcode with a PC relative argument of one or two bytes */
|
/* Emit an opcode with a PC relative argument of one or two bytes */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user