Added new .feature: pc_assignment

git-svn-id: svn://svn.cc65.org/cc65/trunk@310 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2000-09-02 11:05:32 +00:00
parent 5abb3954a6
commit f55d0ccee1
6 changed files with 62 additions and 33 deletions

View File

@@ -147,6 +147,7 @@ void ErrorMsg (const FilePos* Pos, unsigned ErrNum, va_list ap)
"Identifier expected", "Identifier expected",
"`.endmacro' expected", "`.endmacro' expected",
"Option key expected", "Option key expected",
"`=' expected",
"Command is only valid in 65816 mode", "Command is only valid in 65816 mode",
"User error: %s", "User error: %s",
"String constant too long", "String constant too long",

View File

@@ -88,6 +88,7 @@ enum Errors {
ERR_IDENT_EXPECTED, ERR_IDENT_EXPECTED,
ERR_ENDMACRO_EXPECTED, ERR_ENDMACRO_EXPECTED,
ERR_OPTION_KEY_EXPECTED, ERR_OPTION_KEY_EXPECTED,
ERR_EQ_EXPECTED,
ERR_816_MODE_ONLY, ERR_816_MODE_ONLY,
ERR_USER, ERR_USER,
ERR_STRING_TOO_LONG, ERR_STRING_TOO_LONG,

View File

@@ -68,7 +68,7 @@ unsigned char NoColonLabels = 0; /* Allow labels without a colon */
unsigned char LooseStringTerm = 0; /* Allow ' as string terminator */ unsigned char LooseStringTerm = 0; /* Allow ' as string terminator */
unsigned char AtInIdents = 0; /* Allow '@' in identifiers */ unsigned char AtInIdents = 0; /* Allow '@' in identifiers */
unsigned char DollarInIdents = 0; /* Allow '$' in identifiers */ unsigned char DollarInIdents = 0; /* Allow '$' in identifiers */
unsigned char PCAssignment = 0; /* Allow "* = $XXX" or "$ = $XXX" */

View File

@@ -69,6 +69,7 @@ extern unsigned char NoColonLabels; /* Allow labels without a colon */
extern unsigned char LooseStringTerm;/* Allow ' as string terminator */ extern unsigned char LooseStringTerm;/* Allow ' as string terminator */
extern unsigned char AtInIdents; /* Allow '@' in identifiers */ extern unsigned char AtInIdents; /* Allow '@' in identifiers */
extern unsigned char DollarInIdents; /* Allow '$' in identifiers */ extern unsigned char DollarInIdents; /* Allow '$' in identifiers */
extern unsigned char PCAssignment; /* Allow "* = $XXX" or "$ = $XXX" */

View File

@@ -314,6 +314,19 @@ static void OptVersion (const char* Opt, const char* Arg)
static void DoPCAssign (void)
/* Start absolute code */
{
long PC = ConstExpression ();
if (PC < 0 || PC > 0xFFFFFF) {
Error (ERR_RANGE);
} else {
SetAbsPC (PC);
}
}
static void OneLine (void) static void OneLine (void)
/* Assemble one line */ /* Assemble one line */
{ {
@@ -324,49 +337,49 @@ static void OneLine (void)
* and not from internally pushed input. * and not from internally pushed input.
*/ */
if (!HavePushedInput ()) { if (!HavePushedInput ()) {
InitListingLine (); InitListingLine ();
} }
if (Tok == TOK_COLON) { if (Tok == TOK_COLON) {
/* An unnamed label */ /* An unnamed label */
ULabDef (); ULabDef ();
NextTok (); NextTok ();
} }
/* Assemble the line */ /* Assemble the line */
if (Tok == TOK_IDENT) { if (Tok == TOK_IDENT) {
/* Is it a macro? */ /* Is it a macro? */
if (IsMacro (SVal)) { if (IsMacro (SVal)) {
/* Yes, start a macro expansion */ /* Yes, start a macro expansion */
MacExpandStart (); MacExpandStart ();
Done = 1; Done = 1;
} else { } else {
/* No, label. Remember the identifier, then skip it */ /* No, label. Remember the identifier, then skip it */
int HadWS = WS; /* Did we have whitespace before the ident? */ int HadWS = WS; /* Did we have whitespace before the ident? */
strcpy (Ident, SVal); strcpy (Ident, SVal);
NextTok (); NextTok ();
/* If a colon follows, this is a label definition. If there /* If a colon follows, this is a label definition. If there
* is no colon, it's an assignment. * is no colon, it's an assignment.
*/ */
if (Tok == TOK_EQ) { if (Tok == TOK_EQ) {
/* Skip the '=' */ /* Skip the '=' */
NextTok (); NextTok ();
/* Define the symbol with the expression following the '=' */ /* Define the symbol with the expression following the '=' */
SymDef (Ident, Expression (), 0); SymDef (Ident, Expression (), 0);
/* Don't allow anything after a symbol definition */ /* Don't allow anything after a symbol definition */
Done = 1; Done = 1;
} else { } else {
/* Define a label */ /* Define a label */
SymDef (Ident, CurrentPC (), IsZPSeg ()); SymDef (Ident, CurrentPC (), IsZPSeg ());
/* Skip the colon. If NoColonLabels is enabled, allow labels /* Skip the colon. If NoColonLabels is enabled, allow labels
* without a colon if there is no whitespace before the * without a colon if there is no whitespace before the
* identifier. * identifier.
*/ */
if (Tok != TOK_COLON) { if (Tok != TOK_COLON) {
if (HadWS || !NoColonLabels) { if (HadWS || !NoColonLabels) {
Error (ERR_COLON_EXPECTED); Error (ERR_COLON_EXPECTED);
@@ -394,7 +407,18 @@ static void OneLine (void)
} else if (Tok == TOK_IDENT && IsMacro (SVal)) { } else if (Tok == TOK_IDENT && IsMacro (SVal)) {
/* A macro expansion */ /* A macro expansion */
MacExpandStart (); MacExpandStart ();
} } else if (PCAssignment && (Tok == TOK_STAR || Tok == TOK_PC)) {
NextTok ();
if (Tok != TOK_EQ) {
Error (ERR_EQ_EXPECTED);
SkipUntilSep ();
} else {
/* Skip the equal sign */
NextTok ();
/* Enter absolute mode */
DoPCAssign ();
}
}
} }
/* Line separator must come here */ /* Line separator must come here */

View File

@@ -519,6 +519,7 @@ static void DoFeature (void)
"LOOSE_STRING_TERM", "LOOSE_STRING_TERM",
"AT_IN_IDENTIFIERS", "AT_IN_IDENTIFIERS",
"DOLLAR_IN_IDENTIFIERS", "DOLLAR_IN_IDENTIFIERS",
"PC_ASSIGNMENT",
}; };
/* Allow a list of comma separated keywords */ /* Allow a list of comma separated keywords */
@@ -548,6 +549,7 @@ static void DoFeature (void)
case 2: LooseStringTerm = 1; break; case 2: LooseStringTerm = 1; break;
case 3: AtInIdents = 1; break; case 3: AtInIdents = 1; break;
case 4: DollarInIdents = 1; break; case 4: DollarInIdents = 1; break;
case 5: PCAssignment = 1; break;
default: Internal ("Invalid feature: %d", Feature); default: Internal ("Invalid feature: %d", Feature);
} }
@@ -870,7 +872,7 @@ static void DoOrg (void)
/* Start absolute code */ /* Start absolute code */
{ {
long PC = ConstExpression (); long PC = ConstExpression ();
if (PC < 0 || PC > 0xFFFF) { if (PC < 0 || PC > 0xFFFFFF) {
Error (ERR_RANGE); Error (ERR_RANGE);
return; return;
} }