static unsigned OptPtrLoad8 (CodeSeg* S)
+/* Search for the sequence:
+ *
+ * lda zp
+ * ldx zp+1
+ * (anything that doesn't change a/x)
+ * ldy xx
+ * jsr ldauidx
+ *
+ * and replace it by:
+ *
+ * lda zp
+ * ldx zp+1
+ * (anything that doesn't change a/x)
+ * ldy xx
+ * ldx #$00
+ * lda (zp),y
+ *
+ * Must execute before OptPtrLoad10!
+ */
+{
+ unsigned Changes = 0;
+
+ /* Generate register info */
+ CS_GenRegInfo (S);
+
+ /* Walk over the entries */
+ unsigned I = 0;
+ while (I < CS_GetEntryCount (S)) {
+
+ CodeEntry* L[5];
+ unsigned Len;
+
+ /* Get next entry */
+ L[0] = CS_GetEntry (S, I);
+
+ /* Check for the sequence */
+ if (L[0]->OPC == OP65_LDA && L[0]->AM == AM65_ZP &&
+ CS_GetEntries (S, L+1, I+1, 4) &&
+ !CS_RangeHasLabel (S, I+1, 4) &&
+ L[1]->OPC == OP65_LDX && L[1]->AM == AM65_ZP &&
+ (Len = strlen (L[0]->Arg)) > 0 &&
+ strncmp (L[0]->Arg, L[1]->Arg, Len) == 0 &&
+ strcmp (L[1]->Arg + Len, "+1") == 0 &&
+ (L[2]->Chg & REG_AX) == 0 &&
+ L[3]->OPC == OP65_LDY &&
+ CE_IsCallTo (L[4], "ldauidx")) {
+
+ CodeEntry* X;
+
+ /* ldx #$00 */
+ X = NewCodeEntry (OP65_LDX, AM65_IMM, "$00", 0, L[3]->LI);
+ CS_InsertEntry (S, X, I+5);
+
+ /* lda (zp),y */
+ X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, L[0]->Arg, 0, L[3]->LI);
+ CS_InsertEntry (S, X, I+6);
+
+ /* Remove the old code */
+ CS_DelEntry (S, I+4);
+
+ /* Remember, we had changes */
+ ++Changes;
+
+ }
+
+ /* Next entry */
+ ++I;
+
+ }
+
+ /* Free the register info */
+ CS_FreeRegInfo (S);
+
+ /* Return the number of changes made */
+ return Changes;
+}
+
+
+
+static unsigned OptPtrLoad9 (CodeSeg* S)
/* Search for the sequence:
*
* lda zp
-static unsigned OptPtrLoad9 (CodeSeg* S)
+static unsigned OptPtrLoad10 (CodeSeg* S)
/* Search for the sequence
*
* ldy ...
static OptFunc DOptPtrLoad5 = { OptPtrLoad5, "OptPtrLoad5", 92, 0, 0, 0, 0, 0 };
static OptFunc DOptPtrLoad6 = { OptPtrLoad6, "OptPtrLoad6", 50, 0, 0, 0, 0, 0 };
static OptFunc DOptPtrLoad7 = { OptPtrLoad7, "OptPtrLoad7", 65, 0, 0, 0, 0, 0 };
-static OptFunc DOptPtrLoad8 = { OptPtrLoad8, "OptPtrLoad8", 86, 0, 0, 0, 0, 0 };
-static OptFunc DOptPtrLoad9 = { OptPtrLoad9, "OptPtrLoad9", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptPtrLoad8 = { OptPtrLoad8, "OptPtrLoad8", 108, 0, 0, 0, 0, 0 };
+static OptFunc DOptPtrLoad9 = { OptPtrLoad9, "OptPtrLoad9", 86, 0, 0, 0, 0, 0 };
+static OptFunc DOptPtrLoad10 = { OptPtrLoad10, "OptPtrLoad10", 100, 0, 0, 0, 0, 0 };
static OptFunc DOptPtrStore1 = { OptPtrStore1, "OptPtrStore1", 100, 0, 0, 0, 0, 0 };
static OptFunc DOptPtrStore2 = { OptPtrStore2, "OptPtrStore2", 40, 0, 0, 0, 0, 0 };
static OptFunc DOptPush1 = { OptPush1, "OptPush1", 65, 0, 0, 0, 0, 0 };
&DOptNegAX4,
&DOptPrecalc,
&DOptPtrLoad1,
+ &DOptPtrLoad10,
&DOptPtrLoad2,
&DOptPtrLoad3,
&DOptPtrLoad4,
Changes += RunOptFunc (S, &DOptPtrLoad6, 1);
Changes += RunOptFunc (S, &DOptPtrLoad7, 1);
Changes += RunOptFunc (S, &DOptPtrLoad8, 1);
+ Changes += RunOptFunc (S, &DOptPtrLoad9, 1);
Changes += RunOptFunc (S, &DOptNegAX1, 1);
Changes += RunOptFunc (S, &DOptNegAX2, 1);
Changes += RunOptFunc (S, &DOptNegAX3, 1);
do {
C = 0;
- C += RunOptFunc (S, &DOptPtrLoad9, 1);
+ C += RunOptFunc (S, &DOptPtrLoad10, 1);
C += RunOptFunc (S, &DOptNegA1, 1);
C += RunOptFunc (S, &DOptNegA2, 1);
C += RunOptFunc (S, &DOptSub1, 1);
/* Run another round of pattern replacements. These are done late, since there
* may be better replacements before.
*/
-{
+{
unsigned Changes = 0;
Changes += RunOptFunc (S, &DOptPush1, 1);