- /* Add the lda */
- X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, L[4]->Arg, 0, L[0]->LI);
- CS_InsertEntry (S, X, I+3);
-
- /* Add the tay */
- X = NewCodeEntry (OP65_TAY, AM65_IMP, 0, 0, L[0]->LI);
- CS_InsertEntry (S, X, I+4);
-
- /* Add the ldx */
- X = NewCodeEntry (OP65_LDX, AM65_IMM, "$00", 0, L[0]->LI);
- CS_InsertEntry (S, X, I+5);
-
- /* Add the lda */
- Label = memcpy (xmalloc (Len-2), L[0]->Arg+2, Len-3);
- Label[Len-3] = '\0';
- X = NewCodeEntry (OP65_LDA, AM65_ABSY, Label, 0, L[0]->LI);
- CS_InsertEntry (S, X, I+6);
- xfree (Label);
-
- /* Remove the old code */
- CS_DelEntries (S, I, 2);
- CS_DelEntries (S, I+5, 6);
-
- /* Remember, we had changes */
- ++Changes;
-
- }
-
- /* Next entry */
- ++I;
-
- }
-
- /* Return the number of changes made */
- return Changes;
-}
-
-
-
-static unsigned OptPtrLoad5 (CodeSeg* S)
-/* Search for the sequence:
- *
- * lda zp
- * ldx zp+1
- * ldy xx
- * jsr ldauidx
- *
- * and replace it by:
- *
- * ldy xx
- * ldx #$00
- * lda (zp),y
- */
-{
- unsigned Changes = 0;
-
- /* Walk over the entries */
- unsigned I = 0;
- while (I < CS_GetEntryCount (S)) {
-
- CodeEntry* L[4];
- 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, 3) &&
- !CS_RangeHasLabel (S, I+1, 3) &&
- 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]->OPC == OP65_LDY &&
- CE_IsCallTo (L[3], "ldauidx")) {
-
- CodeEntry* X;
-
- /* ldx #$00 */
- X = NewCodeEntry (OP65_LDX, AM65_IMM, "$00", 0, L[3]->LI);
- CS_InsertEntry (S, X, I+3);
-
- /* lda (zp),y */
- X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, L[0]->Arg, 0, L[3]->LI);
- CS_InsertEntry (S, X, I+4);
-
- /* Remove the old code */
- CS_DelEntry (S, I+5);
- CS_DelEntries (S, I, 2);
-
- /* Remember, we had changes */
- ++Changes;
-
- }
-
- /* Next entry */
- ++I;
-
- }
-
- /* Return the number of changes made */
- return Changes;
-}
-
-
-
-static unsigned OptPtrLoad6 (CodeSeg* S)
-/* Search for the sequence:
- *
- * lda zp
- * ldx zp+1
- * ldy xx
- * jsr ldaxidx
- *
- * and replace it by:
- *
- * ldy xx
- * lda (zp),y
- * tax
- * dey
- * lda (zp),y
- */
-{
- unsigned Changes = 0;
-
- /* Walk over the entries */
- unsigned I = 0;
- while (I < CS_GetEntryCount (S)) {
-
- CodeEntry* L[4];
- 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, 3) &&
- !CS_RangeHasLabel (S, I+1, 3) &&
- 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]->OPC == OP65_LDY &&
- CE_IsCallTo (L[3], "ldaxidx")) {