]> git.sur5r.net Git - cc65/commitdiff
Merge pull request #269 from jbrandwood/squarebracket
authorOliver Schmidt <ol.sc@web.de>
Thu, 3 Mar 2016 08:07:21 +0000 (09:07 +0100)
committerOliver Schmidt <ol.sc@web.de>
Thu, 3 Mar 2016 08:07:21 +0000 (09:07 +0100)
New ".feature" to use brackets instead of parens for 6502 indirect addressing.

doc/ca65.sgml
src/ca65/ea65.c
src/ca65/feature.c
src/ca65/feature.h
src/ca65/global.c
src/ca65/global.h

index 213033cd4b3ef100ad8bbf6ac3eeb4dea3fecb47..14fe8714f4eb7a578c618f6207a2b7b14bdb96e3 100644 (file)
@@ -2699,6 +2699,22 @@ Here's a list of all control commands and a description, what they do:
     at character is not allowed to start an identifier, even with this
     feature enabled.
 
+  <tag><tt>bracket_as_indirect</tt><label id="bracket_as_indirect"></tag>
+
+    Use <tt>[]</tt> instead of <tt>()</tt> for the indirect addressing modes.
+    Example:
+
+    <tscreen><verb>
+        lda     [$82]
+        lda     [$82,x]
+        lda     [$82],y
+        jmp     [$fffe]
+        jmp     [table,x]
+    </verb></tscreen>
+    <em/Note:/ This should not be used in 65186 mode because it conflicts with
+    the 65816 instruction syntax for far addressing. See the section covering
+    <tt/<ref id="address-sizes" name="address sizes">/ for more information.
+
   <tag><tt>c_comments</tt><label id="c_comments"></tag>
 
     Allow C like comments using <tt>/*</tt> and <tt>*/</tt> as left and right
index 5f76f2966ce1f49430b8763247d6fde68e543ff9..69468c072102c1465e53c448f6fe5972edf5f182 100644 (file)
@@ -40,6 +40,7 @@
 #include "expr.h"
 #include "instr.h"
 #include "nexttok.h"
+#include "global.h"
 
 
 
@@ -53,6 +54,20 @@ void GetEA (EffAddr* A)
 /* Parse an effective address, return the result in A */
 {
     unsigned long Restrictions;
+    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";
+    }
 
     /* Clear the output struct */
     A->AddrModeSet = 0;
@@ -97,23 +112,7 @@ void GetEA (EffAddr* A)
         NextTok ();
         A->AddrModeSet = AM65_ACCU;
 
-    } else if (CurTok.Tok == TOK_LBRACK) {
-
-        /* [dir] or [dir],y */
-        NextTok ();
-        A->Expr = Expression ();
-        Consume (TOK_RBRACK, "']' expected");
-        if (CurTok.Tok == TOK_COMMA) {
-            /* [dir],y */
-            NextTok ();
-            Consume (TOK_Y, "`Y' expected");
-            A->AddrModeSet = AM65_DIR_IND_LONG_Y;
-        } else {
-            /* [dir] */
-            A->AddrModeSet = AM65_DIR_IND_LONG | AM65_ABS_IND_LONG;
-        }
-
-    } else if (CurTok.Tok == TOK_LPAREN) {
+    } else if (CurTok.Tok == IndirectEnter) {
 
         /* One of the indirect modes */
         NextTok ();
@@ -127,12 +126,12 @@ void GetEA (EffAddr* A)
                 /* (adr,x) */
                 NextTok ();
                 A->AddrModeSet = AM65_ABS_X_IND | AM65_DIR_X_IND;
-                ConsumeRParen ();
+                Consume (IndirectLeave, IndirectExpect);
             } else if (CurTok.Tok == TOK_S) {
                 /* (rel,s),y */
                 NextTok ();
                 A->AddrModeSet = AM65_STACK_REL_IND_Y;
-                ConsumeRParen ();
+                Consume (IndirectLeave, IndirectExpect);
                 ConsumeComma ();
                 Consume (TOK_Y, "`Y' expected");
             } else {
@@ -142,7 +141,7 @@ void GetEA (EffAddr* A)
         } else {
 
             /* (adr) or (adr),y */
-            ConsumeRParen ();
+            Consume (IndirectLeave, IndirectExpect);
             if (CurTok.Tok == TOK_COMMA) {
                 /* (adr),y */
                 NextTok ();
@@ -154,6 +153,23 @@ void GetEA (EffAddr* A)
             }
         }
 
+    } 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 ();
+            Consume (TOK_Y, "`Y' expected");
+            A->AddrModeSet = AM65_DIR_IND_LONG_Y;
+        } else {
+            /* [dir] */
+            A->AddrModeSet = AM65_DIR_IND_LONG | AM65_ABS_IND_LONG;
+        }
+
     } else {
 
         /* Remaining stuff:
index 3462d5501c30848cf3d29d3f9c2cd45938c87fe5..35bdf4b98412438d3d048f7107325ef0b9f10bc4 100644 (file)
@@ -64,6 +64,7 @@ static const char* FeatureKeys[FEAT_COUNT] = {
     "force_range",
     "underline_in_numbers",
     "addrsize",
+    "bracket_as_indirect",
 };
 
 
@@ -121,6 +122,7 @@ feature_t SetFeature (const StrBuf* Key)
         case FEAT_FORCE_RANGE:                ForceRange        = 1;    break;
         case FEAT_UNDERLINE_IN_NUMBERS:       UnderlineInNumbers= 1;    break;
         case FEAT_ADDRSIZE:                   AddrSize          = 1;    break;
+        case FEAT_BRACKET_AS_INDIRECT:        BracketAsIndirect = 1;    break;
         default:                         /* Keep gcc silent */          break;
     }
 
index 3a520a54a3e2ff5eee997eb6214035b7f41490e9..050c197f0659ee13cf15bc05bf193cf0dfdfca81 100644 (file)
@@ -66,6 +66,7 @@ typedef enum {
     FEAT_FORCE_RANGE,
     FEAT_UNDERLINE_IN_NUMBERS,
     FEAT_ADDRSIZE,
+    FEAT_BRACKET_AS_INDIRECT,
 
     /* Special value: Number of features available */
     FEAT_COUNT
index e77b9201c36710b882e564532c9734a42ea09632..31e599f00d0fa7ac70900ad70e0bf8c42a77ce2f 100644 (file)
@@ -83,4 +83,5 @@ unsigned char CComments          = 0;   /* Allow C like comments */
 unsigned char ForceRange         = 0;   /* Force values into expected range */
 unsigned char UnderlineInNumbers = 0;   /* Allow underlines in numbers */
 unsigned char AddrSize           = 0;   /* Allow .ADDRSIZE function */
+unsigned char BracketAsIndirect  = 0;   /* Use '[]' not '()' for indirection */
 
index fb254f835342f13a07379c36ab0555395c4c66ec..397d9221b26c61a01ccb99ae60a98701ea2c45f1 100644 (file)
@@ -85,6 +85,7 @@ extern unsigned char    CComments;          /* Allow C like comments */
 extern unsigned char    ForceRange;         /* Force values into expected range */
 extern unsigned char    UnderlineInNumbers; /* Allow underlines in numbers */
 extern unsigned char    AddrSize;           /* Allow .ADDRSIZE function */
+extern unsigned char    BracketAsIndirect;  /* Use '[]' not '()' for indirection */