From: cuz Date: Sat, 2 Sep 2000 11:05:32 +0000 (+0000) Subject: Added new .feature: pc_assignment X-Git-Tag: V2.12.0~3213 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f55d0ccee17e90763bf3a5ece166366af10e98d7;p=cc65 Added new .feature: pc_assignment git-svn-id: svn://svn.cc65.org/cc65/trunk@310 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/ca65/error.c b/src/ca65/error.c index 221a169f9..1c4663005 100644 --- a/src/ca65/error.c +++ b/src/ca65/error.c @@ -147,6 +147,7 @@ void ErrorMsg (const FilePos* Pos, unsigned ErrNum, va_list ap) "Identifier expected", "`.endmacro' expected", "Option key expected", + "`=' expected", "Command is only valid in 65816 mode", "User error: %s", "String constant too long", diff --git a/src/ca65/error.h b/src/ca65/error.h index 3f377db6c..857d52f18 100644 --- a/src/ca65/error.h +++ b/src/ca65/error.h @@ -88,6 +88,7 @@ enum Errors { ERR_IDENT_EXPECTED, ERR_ENDMACRO_EXPECTED, ERR_OPTION_KEY_EXPECTED, + ERR_EQ_EXPECTED, ERR_816_MODE_ONLY, ERR_USER, ERR_STRING_TOO_LONG, diff --git a/src/ca65/global.c b/src/ca65/global.c index 574654edc..ac3227d80 100644 --- a/src/ca65/global.c +++ b/src/ca65/global.c @@ -68,7 +68,7 @@ unsigned char NoColonLabels = 0; /* Allow labels without a colon */ unsigned char LooseStringTerm = 0; /* Allow ' as string terminator */ unsigned char AtInIdents = 0; /* Allow '@' in identifiers */ unsigned char DollarInIdents = 0; /* Allow '$' in identifiers */ - +unsigned char PCAssignment = 0; /* Allow "* = $XXX" or "$ = $XXX" */ diff --git a/src/ca65/global.h b/src/ca65/global.h index bcca6eca2..759202122 100644 --- a/src/ca65/global.h +++ b/src/ca65/global.h @@ -69,6 +69,7 @@ extern unsigned char NoColonLabels; /* Allow labels without a colon */ extern unsigned char LooseStringTerm;/* Allow ' as string terminator */ extern unsigned char AtInIdents; /* Allow '@' in identifiers */ extern unsigned char DollarInIdents; /* Allow '$' in identifiers */ +extern unsigned char PCAssignment; /* Allow "* = $XXX" or "$ = $XXX" */ diff --git a/src/ca65/main.c b/src/ca65/main.c index 4bfdc2e84..5c96f5048 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -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) /* Assemble one line */ { @@ -324,49 +337,49 @@ static void OneLine (void) * and not from internally pushed input. */ if (!HavePushedInput ()) { - InitListingLine (); + InitListingLine (); } if (Tok == TOK_COLON) { - /* An unnamed label */ - ULabDef (); - NextTok (); + /* An unnamed label */ + ULabDef (); + NextTok (); } /* Assemble the line */ if (Tok == TOK_IDENT) { - /* Is it a macro? */ - if (IsMacro (SVal)) { + /* Is it a macro? */ + if (IsMacro (SVal)) { - /* Yes, start a macro expansion */ - MacExpandStart (); - Done = 1; + /* Yes, start a macro expansion */ + MacExpandStart (); + Done = 1; - } else { + } else { - /* No, label. Remember the identifier, then skip it */ - int HadWS = WS; /* Did we have whitespace before the ident? */ - strcpy (Ident, SVal); - NextTok (); + /* No, label. Remember the identifier, then skip it */ + int HadWS = WS; /* Did we have whitespace before the ident? */ + strcpy (Ident, SVal); + NextTok (); - /* If a colon follows, this is a label definition. If there - * is no colon, it's an assignment. - */ + /* If a colon follows, this is a label definition. If there + * is no colon, it's an assignment. + */ if (Tok == TOK_EQ) { - /* Skip the '=' */ - NextTok (); - /* Define the symbol with the expression following the '=' */ - SymDef (Ident, Expression (), 0); - /* Don't allow anything after a symbol definition */ - Done = 1; - } else { - /* Define a label */ - SymDef (Ident, CurrentPC (), IsZPSeg ()); - /* Skip the colon. If NoColonLabels is enabled, allow labels - * without a colon if there is no whitespace before the - * identifier. - */ + /* Skip the '=' */ + NextTok (); + /* Define the symbol with the expression following the '=' */ + SymDef (Ident, Expression (), 0); + /* Don't allow anything after a symbol definition */ + Done = 1; + } else { + /* Define a label */ + SymDef (Ident, CurrentPC (), IsZPSeg ()); + /* Skip the colon. If NoColonLabels is enabled, allow labels + * without a colon if there is no whitespace before the + * identifier. + */ if (Tok != TOK_COLON) { if (HadWS || !NoColonLabels) { Error (ERR_COLON_EXPECTED); @@ -394,7 +407,18 @@ static void OneLine (void) } else if (Tok == TOK_IDENT && IsMacro (SVal)) { /* A macro expansion */ 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 */ diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c index de2131b8f..58a778034 100644 --- a/src/ca65/pseudo.c +++ b/src/ca65/pseudo.c @@ -519,6 +519,7 @@ static void DoFeature (void) "LOOSE_STRING_TERM", "AT_IN_IDENTIFIERS", "DOLLAR_IN_IDENTIFIERS", + "PC_ASSIGNMENT", }; /* Allow a list of comma separated keywords */ @@ -548,6 +549,7 @@ static void DoFeature (void) case 2: LooseStringTerm = 1; break; case 3: AtInIdents = 1; break; case 4: DollarInIdents = 1; break; + case 5: PCAssignment = 1; break; default: Internal ("Invalid feature: %d", Feature); } @@ -870,7 +872,7 @@ static void DoOrg (void) /* Start absolute code */ { long PC = ConstExpression (); - if (PC < 0 || PC > 0xFFFF) { + if (PC < 0 || PC > 0xFFFFFF) { Error (ERR_RANGE); return; }