cleaned up code per review
This commit is contained in:
@@ -1480,7 +1480,7 @@ unsigned OptPtrLoad18 (CodeSeg* S)
|
|||||||
**
|
**
|
||||||
** This is similar to OptPtrLoad3 but works on a constant address
|
** This is similar to OptPtrLoad3 but works on a constant address
|
||||||
** instead of a label. Also, the initial X and A loads are reversed.
|
** instead of a label. Also, the initial X and A loads are reversed.
|
||||||
** Must be run before OptPtrLoad11.
|
** Must be run before OptPtrLoad7().
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
unsigned Changes = 0;
|
unsigned Changes = 0;
|
||||||
@@ -1512,10 +1512,10 @@ unsigned OptPtrLoad18 (CodeSeg* S)
|
|||||||
CE_IsCallTo (L[7], "ldauidx") &&
|
CE_IsCallTo (L[7], "ldauidx") &&
|
||||||
!CS_RangeHasLabel (S, I+1, 5) &&
|
!CS_RangeHasLabel (S, I+1, 5) &&
|
||||||
!CE_HasLabel (L[7]) &&
|
!CE_HasLabel (L[7]) &&
|
||||||
strlen (L[0]->Arg) == 3 &&
|
|
||||||
L[0]->Arg[0] == '$' &&
|
L[0]->Arg[0] == '$' &&
|
||||||
strlen (L[1]->Arg) == 3 &&
|
L[1]->Arg[0] == '$' &&
|
||||||
L[1]->Arg[0] == '$' ) {
|
strlen (L[0]->Arg) == 3 &&
|
||||||
|
strlen (L[1]->Arg) == 3 ) {
|
||||||
|
|
||||||
CodeEntry* X;
|
CodeEntry* X;
|
||||||
char* Label;
|
char* Label;
|
||||||
@@ -1558,7 +1558,7 @@ unsigned OptPtrLoad19 (CodeSeg* S)
|
|||||||
/* Search for the sequence:
|
/* Search for the sequence:
|
||||||
**
|
**
|
||||||
** ldx #0
|
** ldx #0
|
||||||
** and #mask (any value < 128)
|
** and #mask (any value < 0x80)
|
||||||
** jsr aslax1/shlax1
|
** jsr aslax1/shlax1
|
||||||
** clc
|
** clc
|
||||||
** adc #<(label+0)
|
** adc #<(label+0)
|
||||||
@@ -1572,12 +1572,11 @@ unsigned OptPtrLoad19 (CodeSeg* S)
|
|||||||
**
|
**
|
||||||
** and replace it by:
|
** and replace it by:
|
||||||
**
|
**
|
||||||
** ldx #0
|
** and #mask (remove if == 0x7F)
|
||||||
** and #mask (remove if == 127)
|
** asl
|
||||||
** asl
|
** tay
|
||||||
** tay
|
** lda label,y
|
||||||
** lda label,y
|
** ldx label+1,y
|
||||||
** ldx label+1,y
|
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
unsigned Changes = 0;
|
unsigned Changes = 0;
|
||||||
@@ -1598,10 +1597,8 @@ unsigned OptPtrLoad19 (CodeSeg* S)
|
|||||||
CS_GetEntries (S, L+1, I+1, 11) &&
|
CS_GetEntries (S, L+1, I+1, 11) &&
|
||||||
L[1]->OPC == OP65_AND &&
|
L[1]->OPC == OP65_AND &&
|
||||||
L[1]->AM == AM65_IMM &&
|
L[1]->AM == AM65_IMM &&
|
||||||
CE_HasNumArg (L[1]) && L[1]->Num <= 127 &&
|
CE_HasNumArg (L[1]) && L[1]->Num <= 0x7F &&
|
||||||
L[2]->OPC == OP65_JSR &&
|
L[2]->OPC == OP65_JSR &&
|
||||||
(strcmp (L[2]->Arg, "aslax1") == 0 ||
|
|
||||||
strcmp (L[2]->Arg, "shlax1") == 0) &&
|
|
||||||
L[3]->OPC == OP65_CLC &&
|
L[3]->OPC == OP65_CLC &&
|
||||||
L[4]->OPC == OP65_ADC &&
|
L[4]->OPC == OP65_ADC &&
|
||||||
L[5]->OPC == OP65_TAY &&
|
L[5]->OPC == OP65_TAY &&
|
||||||
@@ -1609,13 +1606,15 @@ unsigned OptPtrLoad19 (CodeSeg* S)
|
|||||||
L[7]->OPC == OP65_ADC &&
|
L[7]->OPC == OP65_ADC &&
|
||||||
L[8]->OPC == OP65_TAX &&
|
L[8]->OPC == OP65_TAX &&
|
||||||
L[9]->OPC == OP65_TYA &&
|
L[9]->OPC == OP65_TYA &&
|
||||||
L[10]->OPC == OP65_LDY &&
|
L[10]->OPC == OP65_LDY &&
|
||||||
CE_IsKnownImm(L[10], 1) &&
|
CE_IsKnownImm(L[10], 1) &&
|
||||||
strlen(L[4]->Arg) >= 3 &&
|
|
||||||
L[4]->Arg[0] == '<' &&
|
L[4]->Arg[0] == '<' &&
|
||||||
strlen(L[7]->Arg) >= 3 &&
|
|
||||||
L[7]->Arg[0] == '>' &&
|
L[7]->Arg[0] == '>' &&
|
||||||
!strcmp(L[4]->Arg+1, L[7]->Arg+1) &&
|
strlen(L[4]->Arg) > 3 &&
|
||||||
|
strlen(L[7]->Arg) > 3 &&
|
||||||
|
strcmp(L[4]->Arg+1, L[7]->Arg+1) == 0 &&
|
||||||
|
(strcmp (L[2]->Arg, "aslax1") == 0 ||
|
||||||
|
strcmp (L[2]->Arg, "shlax1") == 0) &&
|
||||||
CE_IsCallTo (L[11], "ldaxidx") &&
|
CE_IsCallTo (L[11], "ldaxidx") &&
|
||||||
!CS_RangeHasLabel (S, I+1, 11)) {
|
!CS_RangeHasLabel (S, I+1, 11)) {
|
||||||
|
|
||||||
@@ -1634,26 +1633,30 @@ unsigned OptPtrLoad19 (CodeSeg* S)
|
|||||||
X = NewCodeEntry (OP65_TAY, AM65_IMP, 0, 0, L[2]->LI);
|
X = NewCodeEntry (OP65_TAY, AM65_IMP, 0, 0, L[2]->LI);
|
||||||
CS_InsertEntry (S, X, IP++);
|
CS_InsertEntry (S, X, IP++);
|
||||||
|
|
||||||
|
/* allocate Label memory */
|
||||||
|
Label = xmalloc (Len);
|
||||||
/* lda label,y */
|
/* lda label,y */
|
||||||
Label = memcpy (xmalloc (Len-2), L[4]->Arg+2, Len-3);
|
Label = memcpy (Label, L[4]->Arg+2, Len-3);
|
||||||
Label[Len-3] = '\0';
|
Label[Len-3] = '\0';
|
||||||
X = NewCodeEntry (OP65_LDA, AM65_ABSY, Label, 0, L[10]->LI);
|
X = NewCodeEntry (OP65_LDA, AM65_ABSY, Label, 0, L[10]->LI);
|
||||||
CS_InsertEntry (S, X, IP++);
|
CS_InsertEntry (S, X, IP++);
|
||||||
xfree (Label);
|
|
||||||
|
|
||||||
/* lda label+1,y */
|
/* ldx label+1,y */
|
||||||
Label = memcpy (xmalloc (Len), L[4]->Arg+2, Len-3);
|
Label = memcpy (Label, L[4]->Arg+2, Len-3);
|
||||||
strcpy(&Label[Len-3], "+1");
|
strcpy(&Label[Len-3], "+1");
|
||||||
X = NewCodeEntry (OP65_LDX, AM65_ABSY, Label, 0, L[10]->LI);
|
X = NewCodeEntry (OP65_LDX, AM65_ABSY, Label, 0, L[10]->LI);
|
||||||
CS_InsertEntry (S, X, IP++);
|
CS_InsertEntry (S, X, IP++);
|
||||||
|
/* free Label memory */
|
||||||
xfree (Label);
|
xfree (Label);
|
||||||
|
|
||||||
/* Remove the old code */
|
/* Remove the old code */
|
||||||
/* Remove the AND only if it's == 127, since ASL erases high bit */
|
/* Remove the AND only if it's == 0x7F, since ASL erases high bit */
|
||||||
if (L[1]->Num == 127)
|
if (L[1]->Num == 0x7F) {
|
||||||
CS_DelEntries (S, I+1, 11);
|
CS_DelEntries (S, I+1, 11);
|
||||||
else
|
} else {
|
||||||
CS_DelEntries (S, I+2, 10);
|
CS_DelEntries (S, I+2, 10);
|
||||||
|
}
|
||||||
|
|
||||||
/* Remove the ldx #0 */
|
/* Remove the ldx #0 */
|
||||||
CS_DelEntry(S, I);
|
CS_DelEntry(S, I);
|
||||||
|
|
||||||
@@ -1670,6 +1673,3 @@ unsigned OptPtrLoad19 (CodeSeg* S)
|
|||||||
/* Return the number of changes made */
|
/* Return the number of changes made */
|
||||||
return Changes;
|
return Changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -383,7 +383,7 @@ unsigned OptPtrLoad19 (CodeSeg* S);
|
|||||||
/* Search for the sequence:
|
/* Search for the sequence:
|
||||||
**
|
**
|
||||||
** ldx #0
|
** ldx #0
|
||||||
** and #mask (any value < 128)
|
** and #mask (any value < 0x80)
|
||||||
** jsr aslax1/shlax1
|
** jsr aslax1/shlax1
|
||||||
** clc
|
** clc
|
||||||
** adc #<(label+0)
|
** adc #<(label+0)
|
||||||
@@ -397,12 +397,11 @@ unsigned OptPtrLoad19 (CodeSeg* S);
|
|||||||
**
|
**
|
||||||
** and replace it by:
|
** and replace it by:
|
||||||
**
|
**
|
||||||
** ldx #0
|
** and #mask (remove if == 0x7F)
|
||||||
** and #mask (remove if == 127)
|
** asl
|
||||||
** asl
|
** tay
|
||||||
** tay
|
** lda label,y
|
||||||
** lda label,y
|
** ldx label+1,y
|
||||||
** ldx label+1,y
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user