]> git.sur5r.net Git - cc65/commitdiff
Code improvements
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 29 Aug 2009 21:58:06 +0000 (21:58 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 29 Aug 2009 21:58:06 +0000 (21:58 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@4081 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/cc65/codegen.c
src/cc65/coptind.c

index 168f8e5ad142c9204c7e1f3e3af1cbf89270e505..212a07fb4971d8e20cc23f07a34b08cf49ce5754 100644 (file)
@@ -2855,7 +2855,9 @@ void g_and (unsigned Flags, unsigned long Val)
 
             case CF_CHAR:
                 if (Flags & CF_FORCECHAR) {
-                    if ((Val & 0xFF) != 0xFF) {
+                    if ((Val & 0xFF) == 0x00) {
+                        AddCodeLine ("lda #$00");
+                    } else if ((Val & 0xFF) != 0xFF) {
                         AddCodeLine ("and #$%02X", (unsigned char)Val);
                     }
                            return;
@@ -2866,26 +2868,30 @@ void g_and (unsigned Flags, unsigned long Val)
                            if (Val <= 0xFF) {
                                ldxconst (0);
                                if (Val == 0) {
-                                   ldaconst (0);
+                            AddCodeLine ("lda #$00");
                                } else if (Val != 0xFF) {
                                    AddCodeLine ("and #$%02X", (unsigned char)Val);
                                }
-                           } else if ((Val & 0xFF00) == 0xFF00) {
+                           } else if ((Val & 0xFFFF) == 0xFF00) {
+                        AddCodeLine ("lda #$00");
+                    } else if ((Val & 0xFF00) == 0xFF00) {
                                AddCodeLine ("and #$%02X", (unsigned char)Val);
                            } else if ((Val & 0x00FF) == 0x0000) {
                                AddCodeLine ("txa");
                                AddCodeLine ("and #$%02X", (unsigned char)(Val >> 8));
                        AddCodeLine ("tax");
-                       ldaconst (0);
+                       AddCodeLine ("lda #$00");
                     } else {
                        AddCodeLine ("tay");
                        AddCodeLine ("txa");
                        AddCodeLine ("and #$%02X", (unsigned char)(Val >> 8));
                        AddCodeLine ("tax");
                        AddCodeLine ("tya");
-                       if ((Val & 0x00FF) != 0x00FF) {
+                       if ((Val & 0x00FF) == 0x0000) {
+                            AddCodeLine ("lda #$00");
+                       } else if ((Val & 0x00FF) != 0x00FF) {
                                    AddCodeLine ("and #$%02X", (unsigned char)Val);
-                       }
+                        }
                     }
                 }
                 return;
index 6746e06134d9422dcfcdb5b9f4b4c55f96bb70cb..95022e6c102e97ad3a3e668df18d4bd96d8c7c61 100644 (file)
@@ -1845,8 +1845,9 @@ unsigned OptPrecalc (CodeSeg* S)
        /* Get next entry */
                CodeEntry* E = CS_GetEntry (S, I);
 
-               /* Get a pointer to the output registers of the insn */
+               /* Get pointers to the input and output registers of the insn */
                const RegContents* Out = &E->RI->Out;
+        const RegContents* In  = &E->RI->In;
 
         /* Argument for LDn and flag */
         const char* Arg = 0;
@@ -1894,9 +1895,16 @@ unsigned OptPrecalc (CodeSeg* S)
                     /* AND with 0xFF, remove */
                     CS_DelEntry (S, I);
                     ++Changes;
+                } else if (CE_IsKnownImm (E, 0x00)) {
+                    /* AND with 0x00, replace by lda #$00 */
+                    Arg = MakeHexArg (0x00);
                 } else if (RegValIsKnown (Out->RegA)) {
                     /* Accu AND zp with known contents */
                     Arg = MakeHexArg (Out->RegA);
+                } else if (In->RegA == 0xFF) {
+                    /* AND but A contains 0xFF - replace by lda */
+                    CE_ReplaceOPC (E, OP65_LDA);
+                    ++Changes;
                 }
                 break;
 
@@ -1905,9 +1913,16 @@ unsigned OptPrecalc (CodeSeg* S)
                     /* ORA with zero, remove */
                     CS_DelEntry (S, I);
                     ++Changes;
+                } else if (CE_IsKnownImm (E, 0xFF)) {
+                    /* ORA with 0xFF, replace by lda #$ff */
+                    Arg = MakeHexArg (0xFF);
                 } else if (RegValIsKnown (Out->RegA)) {
                     /* Accu AND zp with known contents */
                     Arg = MakeHexArg (Out->RegA);
+                } else if (In->RegA == 0) {
+                    /* ORA but A contains 0x00 - replace by lda */
+                    CE_ReplaceOPC (E, OP65_LDA);
+                    ++Changes;
                 }
                 break;