]> git.sur5r.net Git - cc65/blobdiff - src/ca65/instr.c
More lineinfo usage.
[cc65] / src / ca65 / instr.c
index 1603dcd9f1d7cb5564667b54d22ef7847bb2afaa..39c32f2eadc91464c4ce2ba0a7ef04c88d52b2d4 100644 (file)
@@ -6,8 +6,8 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2005, Ullrich von Bassewitz                                      */
-/*                Römerstrasse 52                                            */
+/* (C) 1998-2011, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
 /*                                                                           */
@@ -39,7 +39,6 @@
 
 /* common */
 #include "addrsize.h"
-#include "assertdefs.h"
 #include "attrib.h"
 #include "bitops.h"
 #include "check.h"
@@ -490,9 +489,7 @@ static const struct {
                { "BCC",  0x0020000, 0x90, 0, PutPCRel8 },
                { "BCS",  0x0020000, 0xb0, 0, PutPCRel8 },
                { "BEQ",  0x0020000, 0xf0, 0, PutPCRel8 },
-               { "BGE",  0x0020000, 0xb0, 0, PutPCRel8 },   /* == BCS */
                { "BIT",  0x0a0006c, 0x00, 2, PutAll },
-               { "BLT",  0x0020000, 0x90, 0, PutPCRel8 },   /* == BCC */
                { "BMI",  0x0020000, 0x30, 0, PutPCRel8 },
                { "BNE",  0x0020000, 0xd0, 0, PutPCRel8 },
                { "BPL",  0x0020000, 0x10, 0, PutPCRel8 },
@@ -625,7 +622,7 @@ static const struct {
         { "ST",   AMSW16_REG | AMSW16_IND, 0x10, 1, PutSweet16 },
         { "STD",  AMSW16_IND,              0x70, 0, PutSweet16 },
         { "STP",  AMSW16_IND,              0x90, 0, PutSweet16 },
-        { "SUB",  AMSW16_IMM,              0xB0, 0, PutSweet16 },
+        { "SUB",  AMSW16_REG,              0xB0, 0, PutSweet16 },
     }
 };
 
@@ -946,11 +943,19 @@ static int EvalEA (const InsDesc* Ins, EffAddr* A)
         /* Simplify it if possible */
         A->Expr = SimplifyExpr (A->Expr, &ED);
 
-        /* If we don't know how big the expression is, assume the default
-         * address size for data.
-         */
         if (ED.AddrSize == ADDR_SIZE_DEFAULT) {
+            /* If we don't know how big the expression is, assume the
+             * default address size for data. If this default address
+             * size is unequal to zero page addressing, but zero page
+             * addressing is allowed by the instruction, mark all symbols
+             * in the expression tree. This mark will be checked at end
+             * of assembly, and a warning is issued, if a zero page symbol
+             * was guessed wrong here.
+             */
             ED.AddrSize = DataAddrSize;
+            if (ED.AddrSize > ADDR_SIZE_ZP && (A->AddrModeSet & AM65_SET_ZP)) {
+                ExprGuessedAddrSize (A->Expr, ADDR_SIZE_ZP);
+            }
         }
 
         /* Check the size */
@@ -1250,7 +1255,7 @@ static void PutTST (const InsDesc* Ins)
     EffAddr   A;
 
     /* The first argument is always an immediate byte */
-    if (Tok != TOK_HASH) {
+    if (CurTok.Tok != TOK_HASH) {
         ErrorSkip ("Invalid addressing mode");
         return;
     }
@@ -1427,7 +1432,7 @@ void SetCPU (cpu_t NewCPU)
     CHECK (NewCPU < CPU_COUNT);
 
     /* Check if we have support for the new CPU, if so, use it */
-    if (InsTabs[NewCPU]) {
+    if (NewCPU != CPU_UNKNOWN && InsTabs[NewCPU]) {
        CPU = NewCPU;
        InsTab = InsTabs[CPU];
     } else {
@@ -1445,7 +1450,7 @@ cpu_t GetCPU (void)
 
 
 
-int FindInstruction (const char* Ident)
+int FindInstruction (const StrBuf* Ident)
 /* Check if Ident is a valid mnemonic. If so, return the index in the
  * instruction table. If not, return -1.
  */
@@ -1464,7 +1469,7 @@ int FindInstruction (const char* Ident)
 
     /* Make a copy, and uppercase that copy */
     I = 0;
-    while (Ident[I] != '\0') {
+    while (I < SB_GetLen (Ident)) {
         /* If the identifier is longer than the longest mnemonic, it cannot
          * be one.
          */
@@ -1472,7 +1477,7 @@ int FindInstruction (const char* Ident)
             /* Not found, no need for further action */
             return -1;
         }
-        Key[I] = toupper ((unsigned char)Ident[I]);
+        Key[I] = toupper ((unsigned char)SB_AtUnchecked (Ident, I));
         ++I;
     }
     Key[I] = '\0';