+static unsigned OptLoad2 (CodeSeg* S)
+/* Replace calls to ldaxysp by inline code */
+{
+ unsigned I;
+ unsigned Changes = 0;
+
+ /* Walk over the entries */
+ I = 0;
+ while (I < CS_GetEntryCount (S)) {
+
+ CodeEntry* E;
+
+ /* Get next entry */
+ E = CS_GetEntry (S, I);
+
+ /* Check for the sequence */
+ if (CE_IsCallTo (E, "ldaxysp")) {
+
+ CodeEntry* X;
+
+ /* lda (sp),y */
+ X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "sp", 0, E->LI);
+ CS_InsertEntry (S, X, I+1);
+
+ /* tax */
+ X = NewCodeEntry (OP65_TAX, AM65_IMP, 0, 0, E->LI);
+ CS_InsertEntry (S, X, I+2);
+
+ /* dey */
+ X = NewCodeEntry (OP65_DEY, AM65_IMP, 0, 0, E->LI);
+ CS_InsertEntry (S, X, I+3);
+
+ /* lda (sp),y */
+ X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "sp", 0, E->LI);
+ CS_InsertEntry (S, X, I+4);
+
+ /* Now remove the call to the subroutine */
+ CS_DelEntry (S, I);
+
+ /* Remember, we had changes */
+ ++Changes;
+
+ }
+
+ /* Next entry */
+ ++I;
+ }
+
+ /* Return the number of changes made */
+ return Changes;
+}
+
+
+