Skip to content

Commit 797e4ea

Browse files
committed
optimization
1 parent 55bd108 commit 797e4ea

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/include/opt6502/opt_ADD.inc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,43 @@ begin
103103
end;
104104

105105

106+
if lda_val(i) and (iy(i) = false) and // lda ; 0
107+
((listing[i+1] = #9'add #$01') or (listing[i+1] = #9'sub #$01')) and // add #$01|sub #$01 ; 1
108+
sta_val(i+2) and (iy(i+2) = false) and // sta ; 2
109+
lda_a(i+3) and // lda ; 3
110+
(add_sub(i+4) or sta_a(i+4)) then // add|sub|sta ; 4
111+
begin
112+
listing[i] := #9'ldy ' + copy(listing[i], 6, 256);
113+
114+
if listing[i+1] = #9'add #$01' then
115+
listing[i+1] := #9'iny'
116+
else
117+
listing[i+1] := #9'dey';
118+
119+
listing[i+2] := #9'sty ' + copy(listing[i+2], 6, 256);
120+
121+
exit(false);
122+
end;
123+
124+
125+
if lda_val(i) and (iy(i) = false) and // lda ; 0
126+
((listing[i+1] = #9'add #$01') or (listing[i+1] = #9'sub #$01')) and // add #$01|sub #$01 ; 1
127+
sta_val(i+2) and (iy(i+2) = false) and // sta ; 2
128+
ldy(i+3) then // ldy ; 3
129+
begin
130+
listing[i] := #9'ldy ' + copy(listing[i], 6, 256);
131+
132+
if listing[i+1] = #9'add #$01' then
133+
listing[i+1] := #9'iny'
134+
else
135+
listing[i+1] := #9'dey';
136+
137+
listing[i+2] := #9'sty ' + copy(listing[i+2], 6, 256);
138+
139+
exit(false);
140+
end;
141+
142+
106143
if lda_a(i) and (iy(i) = false) and // lda ; 0
107144
add_sub(i+1) and // add|sub ; 1
108145
sta_stack(i+2) and // sta :STACKORIGIN ; 2

0 commit comments

Comments
 (0)