2004-10-03 21:26:00 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* */
|
2013-05-09 11:56:54 +00:00
|
|
|
/* ea65.c */
|
2004-10-03 21:26:00 +00:00
|
|
|
/* */
|
|
|
|
/* 65XX effective address parsing for the ca65 macroassembler */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* */
|
2011-01-16 16:05:43 +00:00
|
|
|
/* (C) 1998-2011, Ullrich von Bassewitz */
|
|
|
|
/* Roemerstrasse 52 */
|
|
|
|
/* D-70794 Filderstadt */
|
|
|
|
/* EMail: uz@cc65.org */
|
2004-10-03 21:26:00 +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. */
|
|
|
|
/* */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ca65 */
|
|
|
|
#include "ea.h"
|
|
|
|
#include "ea65.h"
|
|
|
|
#include "error.h"
|
|
|
|
#include "expr.h"
|
|
|
|
#include "instr.h"
|
|
|
|
#include "nexttok.h"
|
2016-02-25 20:40:31 +00:00
|
|
|
#include "global.h"
|
2004-10-03 21:26:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Code */
|
2004-10-03 21:26:00 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GetEA (EffAddr* A)
|
|
|
|
/* Parse an effective address, return the result in A */
|
|
|
|
{
|
|
|
|
unsigned long Restrictions;
|
2016-02-25 20:40:31 +00:00
|
|
|
token_t IndirectEnter;
|
|
|
|
token_t IndirectLeave;
|
|
|
|
const char* IndirectExpect;
|
|
|
|
|
|
|
|
/* Choose syntax for indirection */
|
|
|
|
if (BracketAsIndirect) {
|
|
|
|
IndirectEnter = TOK_LBRACK;
|
|
|
|
IndirectLeave = TOK_RBRACK;
|
|
|
|
IndirectExpect = "']' expected";
|
|
|
|
} else {
|
|
|
|
IndirectEnter = TOK_LPAREN;
|
|
|
|
IndirectLeave = TOK_RPAREN;
|
|
|
|
IndirectExpect = "')' expected";
|
|
|
|
}
|
2004-10-03 21:26:00 +00:00
|
|
|
|
|
|
|
/* Clear the output struct */
|
|
|
|
A->AddrModeSet = 0;
|
|
|
|
A->Expr = 0;
|
|
|
|
|
|
|
|
/* Handle an addressing size override */
|
2011-01-16 16:05:43 +00:00
|
|
|
switch (CurTok.Tok) {
|
2004-10-03 21:26:00 +00:00
|
|
|
case TOK_OVERRIDE_ZP:
|
|
|
|
Restrictions = AM65_DIR | AM65_DIR_X | AM65_DIR_Y;
|
|
|
|
NextTok ();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOK_OVERRIDE_ABS:
|
|
|
|
Restrictions = AM65_ABS | AM65_ABS_X | AM65_ABS_Y;
|
|
|
|
NextTok ();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOK_OVERRIDE_FAR:
|
|
|
|
Restrictions = AM65_ABS_LONG | AM65_ABS_LONG_X;
|
|
|
|
NextTok ();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Restrictions = ~0UL; /* None */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse the effective address */
|
2011-01-16 16:05:43 +00:00
|
|
|
if (TokIsSep (CurTok.Tok)) {
|
2004-10-03 21:26:00 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
A->AddrModeSet = AM65_IMPLICIT;
|
2004-10-03 21:26:00 +00:00
|
|
|
|
2011-01-16 16:05:43 +00:00
|
|
|
} else if (CurTok.Tok == TOK_HASH) {
|
2004-10-03 21:26:00 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
/* #val */
|
|
|
|
NextTok ();
|
|
|
|
A->Expr = Expression ();
|
|
|
|
A->AddrModeSet = AM65_ALL_IMM;
|
2004-10-03 21:26:00 +00:00
|
|
|
|
2011-01-16 16:05:43 +00:00
|
|
|
} else if (CurTok.Tok == TOK_A) {
|
2004-10-03 21:26:00 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
NextTok ();
|
|
|
|
A->AddrModeSet = AM65_ACCU;
|
2004-10-03 21:26:00 +00:00
|
|
|
|
2016-02-25 20:40:31 +00:00
|
|
|
} else if (CurTok.Tok == IndirectEnter) {
|
2004-10-03 21:26:00 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
/* One of the indirect modes */
|
|
|
|
NextTok ();
|
|
|
|
A->Expr = Expression ();
|
|
|
|
|
|
|
|
if (CurTok.Tok == TOK_COMMA) {
|
|
|
|
|
|
|
|
/* (expr,X) or (rel,S),y */
|
|
|
|
NextTok ();
|
|
|
|
if (CurTok.Tok == TOK_X) {
|
|
|
|
/* (adr,x) */
|
|
|
|
NextTok ();
|
|
|
|
A->AddrModeSet = AM65_ABS_X_IND | AM65_DIR_X_IND;
|
2016-02-25 20:40:31 +00:00
|
|
|
Consume (IndirectLeave, IndirectExpect);
|
2013-05-09 11:56:54 +00:00
|
|
|
} else if (CurTok.Tok == TOK_S) {
|
|
|
|
/* (rel,s),y */
|
|
|
|
NextTok ();
|
|
|
|
A->AddrModeSet = AM65_STACK_REL_IND_Y;
|
2016-02-25 20:40:31 +00:00
|
|
|
Consume (IndirectLeave, IndirectExpect);
|
2013-05-09 11:56:54 +00:00
|
|
|
ConsumeComma ();
|
2019-01-05 19:57:12 +00:00
|
|
|
Consume (TOK_Y, "'Y' expected");
|
2013-05-09 11:56:54 +00:00
|
|
|
} else {
|
|
|
|
Error ("Syntax error");
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2016-08-29 08:45:18 +00:00
|
|
|
/* (adr), (adr),y or (adr),z */
|
2016-02-25 20:40:31 +00:00
|
|
|
Consume (IndirectLeave, IndirectExpect);
|
2013-05-09 11:56:54 +00:00
|
|
|
if (CurTok.Tok == TOK_COMMA) {
|
|
|
|
/* (adr),y */
|
|
|
|
NextTok ();
|
2016-08-29 21:29:31 +00:00
|
|
|
switch (CurTok.Tok) {
|
2016-08-29 08:45:18 +00:00
|
|
|
case TOK_Z:
|
2016-08-29 21:29:31 +00:00
|
|
|
/* only set by scanner.c if in 4510-mode */
|
|
|
|
NextTok ();
|
|
|
|
A->AddrModeSet = AM65_DIR_IND;
|
2016-08-29 08:45:18 +00:00
|
|
|
break;
|
|
|
|
default:
|
2019-01-05 19:57:12 +00:00
|
|
|
Consume (TOK_Y, "'Y' expected");
|
2016-08-29 08:45:18 +00:00
|
|
|
A->AddrModeSet = AM65_DIR_IND_Y;
|
|
|
|
break;
|
|
|
|
}
|
2013-05-09 11:56:54 +00:00
|
|
|
} else {
|
|
|
|
/* (adr) */
|
2016-08-29 08:45:18 +00:00
|
|
|
A->AddrModeSet = (CPU == CPU_4510) ? AM65_ABS_IND
|
|
|
|
: AM65_ABS_IND | AM65_ABS_IND_LONG | AM65_DIR_IND;
|
2013-05-09 11:56:54 +00:00
|
|
|
}
|
|
|
|
}
|
2004-10-03 21:26:00 +00:00
|
|
|
|
2016-02-25 20:40:31 +00:00
|
|
|
} else if (CurTok.Tok == TOK_LBRACK) {
|
|
|
|
|
|
|
|
/* Never executed if BracketAsIndirect feature is enabled. */
|
|
|
|
/* [dir] or [dir],y */
|
|
|
|
NextTok ();
|
|
|
|
A->Expr = Expression ();
|
|
|
|
Consume (TOK_RBRACK, "']' expected");
|
|
|
|
if (CurTok.Tok == TOK_COMMA) {
|
|
|
|
/* [dir],y */
|
|
|
|
NextTok ();
|
2019-01-05 19:57:12 +00:00
|
|
|
Consume (TOK_Y, "'Y' expected");
|
2016-02-25 20:40:31 +00:00
|
|
|
A->AddrModeSet = AM65_DIR_IND_LONG_Y;
|
|
|
|
} else {
|
|
|
|
/* [dir] */
|
|
|
|
A->AddrModeSet = AM65_DIR_IND_LONG | AM65_ABS_IND_LONG;
|
|
|
|
}
|
|
|
|
|
2004-10-03 21:26:00 +00:00
|
|
|
} else {
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Remaining stuff:
|
2014-06-30 09:10:35 +00:00
|
|
|
**
|
|
|
|
** adr
|
|
|
|
** adr,x
|
|
|
|
** adr,y
|
|
|
|
** adr,s
|
|
|
|
*/
|
2013-05-09 11:56:54 +00:00
|
|
|
A->Expr = Expression ();
|
2004-10-03 21:26:00 +00:00
|
|
|
|
2011-01-16 16:05:43 +00:00
|
|
|
if (CurTok.Tok == TOK_COMMA) {
|
2004-10-03 21:26:00 +00:00
|
|
|
|
|
|
|
NextTok ();
|
2011-01-16 16:05:43 +00:00
|
|
|
switch (CurTok.Tok) {
|
2004-10-03 21:26:00 +00:00
|
|
|
|
|
|
|
case TOK_X:
|
|
|
|
A->AddrModeSet = AM65_ABS_LONG_X | AM65_ABS_X | AM65_DIR_X;
|
|
|
|
NextTok ();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOK_Y:
|
|
|
|
A->AddrModeSet = AM65_ABS_Y | AM65_DIR_Y;
|
|
|
|
NextTok ();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOK_S:
|
|
|
|
A->AddrModeSet = AM65_STACK_REL;
|
|
|
|
NextTok ();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Error ("Syntax error");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
A->AddrModeSet = AM65_ABS_LONG | AM65_ABS | AM65_DIR;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Apply addressing mode overrides */
|
|
|
|
A->AddrModeSet &= Restrictions;
|
|
|
|
}
|