Skip to content

Commit f850226

Browse files
committed
bugfixes and optimizations
1 parent d8b5fba commit f850226

File tree

10 files changed

+208
-152
lines changed

10 files changed

+208
-152
lines changed

origin/include/cmd_temporary.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11

2+
function MWY(i: integer): Boolean;
3+
begin
4+
Result := pos(#9'mwy ', TemporaryBuf[i]) = 1
5+
end;
6+
7+
function MVY(i: integer): Boolean;
8+
begin
9+
Result := pos(#9'mvy ', TemporaryBuf[i]) = 1
10+
end;
11+
212
function MVA(i: integer): Boolean;
313
begin
414
Result := pos(#9'mva ', TemporaryBuf[i]) = 1

origin/include/opt6502/opt_ADD.inc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ begin
7070
adc_stack(i+4) and // adc :STACKORIGIN+STACKWIDTH ; 4
7171
sta_stack(i+5) and // sta :STACKORIGIN+STACKWIDTH ; 5
7272
lda_stack(i+6) and // lda :STACKORIGIN ; 6
73-
add_im(i+7) and // add # ; 7
73+
add_im(i+7) and (data(i+7) = false) and // add # ; 7
7474
sta_stack(i+8) and // sta :STACKORIGIN ; 8
7575
lda_stack(i+9) and // lda :STACKORIGIN+STACKWIDTH ; 9
7676
adc_im(i+10) and // adc # ; 10
@@ -107,7 +107,7 @@ begin
107107
adc(i+3) and // adc ; 3
108108
sta_stack(i+4) and // sta :STACKORIGIN+STACKWIDTH ; 4
109109
lda_stack(i+5) and // lda :STACKORIGIN ; 5
110-
add_im(i+6) and // add # ; 6
110+
add_im(i+6) and (data(i+6) = false) and // add # ; 6
111111
sta_stack(i+7) and // sta :STACKORIGIN ; 7
112112
lda_stack(i+8) and // lda :STACKORIGIN+STACKWIDTH ; 8
113113
adc_im(i+9) and // adc # ; 9
@@ -1161,7 +1161,7 @@ begin
11611161
if adc_im(i+4) and // adc # ; 4
11621162

11631163
lda_im(i) and // lda # ; 0
1164-
add_im(i+1) and // add # ; 1
1164+
add_im(i+1) and (data(i+1) = false) and // add # ; 1
11651165
sta_a(i+2) and // sta ; 2
11661166
lda_im(i+3) and // lda # ; 3
11671167
// adc_im(i+4) and // adc # ; 4
@@ -1455,7 +1455,7 @@ begin
14551455
adc(i+4) and // adc ; 4
14561456
sta_stack(i+5) and // sta :STACKORIGIN+STACKWIDTH+9 ; 5
14571457
lda_stack(i+6) and // lda :STACKORIGIN+9 ; 6
1458-
add_im(i+7) and // add # ; 7
1458+
add_im(i+7) and (data(i+7) = false) and // add # ; 7
14591459
sta_a(i+8) and // sta P ; 8
14601460
lda_stack(i+9) and // lda :STACKORIGIN+STACKWIDTH+9 ; 9
14611461
// adc_im(i+10) and // adc #$00 ; 10
@@ -1759,14 +1759,14 @@ begin
17591759
if adc_im(i+11) and // adc # ; 11
17601760

17611761
lda_a(i) and // lda W ; 0
1762-
add_im(i+1) and // add # ; 1
1762+
add_im(i+1) and (data(i+1) = false) and // add # ; 1
17631763
sta_stack(i+2) and // sta :STACKORIGIN+9 ; 2
17641764
iny(i+3) and // iny ; 3
17651765
lda_a(i+4) and // lda W+1 ; 4
17661766
adc_im(i+5) and // adc # ; 5
17671767
sta_stack(i+6) and // sta :STACKORIGIN+STACKWIDTH+9 ; 6
17681768
lda_stack(i+7) and // lda :STACKORIGIN+9 ; 7
1769-
add_im(i+8) and // add # ; 8
1769+
add_im(i+8) and (data(i+8) = false) and // add # ; 8
17701770
sta_a(i+9) and // sta W ; 9
17711771
lda_stack(i+10) and // lda :STACKORIGIN+STACKWIDTH+9 ; 10
17721772
// adc_im(i+11) and // adc # ; 11
@@ -1803,7 +1803,7 @@ begin
18031803
adc(i+5) and // adc ; 5
18041804
sta_stack(i+6) and // sta :STACKORIGIN+STACKWIDTH+9 ; 6
18051805
lda_stack(i+7) and // lda :STACKORIGIN+9 ; 7
1806-
add_im(i+8) and // add # ; 8
1806+
add_im(i+8) and (data(i+8) = false) and // add # ; 8
18071807
sta_a(i+9) and // sta W ; 9
18081808
lda_stack(i+10) and // lda :STACKORIGIN+STACKWIDTH+9 ; 10
18091809
// adc_im(i+11) and // adc # ; 11
@@ -1917,13 +1917,13 @@ begin
19171917
if adc_im(i+10) and // adc # ; 10
19181918

19191919
lda_a(i) and // lda W ; 0
1920-
add_im(i+1) and // add # ; 1
1920+
add_im(i+1) and (data(i+1) = false) and // add # ; 1
19211921
sta_stack(i+2) and // sta :STACKORIGIN+9 ; 2
19221922
lda_a(i+3) and // lda W+1 ; 3
19231923
adc_im(i+4) and // adc # ; 4
19241924
sta_stack(i+5) and // sta :STACKORIGIN+STACKWIDTH+9 ; 5
19251925
lda_stack(i+6) and // lda :STACKORIGIN+9 ; 6
1926-
add_im(i+7) and // add # ; 7
1926+
add_im(i+7) and (data(i+7) = false) and // add # ; 7
19271927
sta_a(i+8) and // sta W ; 8
19281928
lda_stack(i+9) and // lda :STACKORIGIN+STACKWIDTH+9 ; 9
19291929
// adc_im(i+10) and // adc # ; 10

origin/include/opt6502/opt_STACK.inc

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ begin
346346
exit(false);
347347
end;
348348

349+
349350
if (listing[i] = #9'sta :STACKORIGIN-1,x') and // sta :STACKORIGIN-1,x ; 0
350351
dex(i+1) then // dex ; 1
351352
begin
@@ -460,7 +461,7 @@ begin
460461
mva(i+1) and // mva :STACKORIGIN,x ; 1
461462
(listing[i+2] = #9'ldy :STACKORIGIN-1,x') and // ldy :STACKORIGIN-1,x ; 2
462463
(listing[i+3] = #9'lda :STACKORIGIN,x') and // lda :STACKORIGIN,x ; 3
463-
sta_val(i+4) then // sta ~:STACKORIGIN ; 4
464+
sta_val(i+4) then // sta ; 4 ~:STACKORIGIN
464465
if (pos(':STACKORIGIN,x', listing[i+1]) > 0) then
465466
begin
466467
listing[i+3] := #9'lda ' + GetString(i+1);
@@ -476,7 +477,7 @@ begin
476477
mwy_bp2(i+2) and // mwy G :bp2 ; 2
477478
(listing[i+3] = #9'ldy :STACKORIGIN-1,x') and // ldy :STACKORIGIN-1,x ; 3
478479
(listing[i+4] = #9'lda :STACKORIGIN,x') and // lda :STACKORIGIN,x ; 4
479-
sta_val(i+5) then // sta ~:STACKORIGIN ; 5
480+
sta_val(i+5) then // sta ; 5 ~:STACKORIGIN
480481
if (pos(':STACKORIGIN,x', listing[i+1]) > 0) then
481482
begin
482483
listing[i+4] := #9'lda ' + GetString(i+1);
@@ -736,14 +737,14 @@ begin
736737
mva(i+1) and // mva :STACKORIGIN,x ; 1
737738
mva(i+2) and // mva :STACKORIGIN+STACKWIDTH,x ; 2
738739
inx(i+3) and // inx ; 3
739-
lda_val(i+4) and // lda ~:STACKORIGIN ; 4
740-
sta_val(i+5) and // sta ~:STACKORIGIN ; 5
741-
lda_val(i+6) and // lda ~:STACKORIGIN ; 6
742-
sta_val(i+7) and // sta ~:STACKORIGIN ; 7
740+
lda_val(i+4) and // lda ; 4 ~:STACKORIGIN
741+
sta_val(i+5) and // sta ; 5 ~:STACKORIGIN
742+
lda_val(i+6) and // lda ; 6 ~:STACKORIGIN
743+
sta_val(i+7) and // sta ; 7 ~:STACKORIGIN
743744
(listing[i+8] = #9'lda :STACKORIGIN-1,x') and // lda :STACKORIGIN-1,x ; 8
744-
sta_val(i+9) and // sta ~:STACKORIGIN ; 9
745+
sta_val(i+9) and // sta ; 9 ~:STACKORIGIN
745746
(listing[i+10] = #9'lda :STACKORIGIN-1+STACKWIDTH,x') and // lda :STACKORIGIN-1+STACKWIDTH,x ; 10
746-
sta_val(i+11) then // sta ~:STACKORIGIN ; 11
747+
sta_val(i+11) then // sta ; 11 ~:STACKORIGIN
747748
if (pos(':STACKORIGIN,x', listing[i+1]) > 0) and
748749
(pos(':STACKORIGIN+STACKWIDTH,x', listing[i+2]) > 0) then
749750
begin
@@ -1851,17 +1852,17 @@ begin
18511852

18521853

18531854
if inx(i) and // inx ; 0
1854-
lda_val(i+1) and (iy(i+1) = false) and // lda ~:STACKORIGIN ; 1
1855-
add_sub_val(i+2) and // add|sub ~:STACKORIGIN ; 2
1855+
lda_val(i+1) and (iy(i+1) = false) and // lda ; 1 ~:STACKORIGIN
1856+
add_sub_val(i+2) and // add|sub ; 2 ~:STACKORIGIN
18561857
(listing[i+3] = #9'sta :STACKORIGIN,x') and // sta :STACKORIGIN ; 3
1857-
lda_val(i+4) and (iy(i+4) = false) and // lda ~:STACKORIGIN ; 4
1858-
adc_sbc_val(i+5) and // adc|sbc ~:STACKORIGIN ; 5
1858+
lda_val(i+4) and (iy(i+4) = false) and // lda ; 4 ~:STACKORIGIN
1859+
adc_sbc_val(i+5) and // adc|sbc ; 5 ~:STACKORIGIN
18591860
(listing[i+6] = #9'sta :STACKORIGIN+STACKWIDTH,x') and // sta :STACKORIGIN+STACKWIDTH ; 6
18601861
(listing[i+7] = #9'ldy :STACKORIGIN-1,x') and // ldy :STACKORIGIN-1,x ; 7
18611862
(listing[i+8] = #9'lda :STACKORIGIN,x') and // lda :STACKORIGIN,x ; 8
1862-
sta_val(i+9) and // sta ~:STACKORIGIN ; 9
1863+
sta_val(i+9) and // sta ; 9 ~:STACKORIGIN
18631864
(listing[i+10] = #9'lda :STACKORIGIN+STACKWIDTH,x') and // lda :STACKORIGIN+STACKWIDTH ; 10
1864-
sta_val(i+11) and // sta ~:STACKORIGIN ; 11
1865+
sta_val(i+11) and // sta ; 11 ~:STACKORIGIN
18651866
(lda_a(i+12) = false) then //~lda ; 12
18661867
begin
18671868
listing[i+3] := listing[i+9];

origin/include/opt6502/opt_STACK_PRINT.inc

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
function opt_STACK_PRINT(i: integer): Boolean;
33
var p: integer;
44
tmp: string;
5+
6+
7+
function fail(i: integer): Boolean;
8+
begin
9+
10+
Result := jsr(i) or
11+
dex(i) or
12+
(pos(#9'@print', listing[i]) > 0);
13+
14+
end;
15+
16+
517
begin
618

719
Result := true;
@@ -101,7 +113,7 @@ begin
101113

102114
if dex(i+7) then
103115
for p:=i-1 downto 0 do
104-
if jsr(p) then Break else
116+
if fail(p) then Break else
105117
if inx(p) then begin listing[i+7] := ''; listing[p] := ''; Break end;
106118

107119
exit(false);
@@ -123,7 +135,7 @@ begin
123135

124136
if dex(i+5) then
125137
for p:=i-1 downto 0 do
126-
if jsr(p) then Break else
138+
if fail(p) then Break else
127139
if inx(p) then begin listing[i+5] := ''; listing[p] := ''; Break end;
128140

129141
exit(false);
@@ -155,7 +167,7 @@ begin
155167

156168
if dex(i+2) then
157169
for p:=i-1 downto 0 do
158-
if jsr(p) then Break else
170+
if fail(p) then Break else
159171
if inx(p) then begin listing[i+2] := ''; listing[p] := ''; Break end;
160172

161173
exit(false);
@@ -201,13 +213,12 @@ begin
201213
sta_stack(i) then // sta :STACKORIGIN,x ; 0
202214
// (listing[i+1] = #9'jsr @printBYTE') then // jsr @printBYTE ; 1
203215
begin
204-
205216
listing[i] := '';
206217
listing[i+1] := #9'jsr @printBYTE._a';
207218

208219
if dex(i+2) then
209220
for p:=i-1 downto 0 do
210-
if jsr(p) then Break else
221+
if fail(p) then Break else
211222
if inx(p) then begin listing[i+2] := ''; listing[p] := ''; Break end;
212223

213224
exit(false);
@@ -220,13 +231,12 @@ begin
220231
// (listing[i+1] = #9'jsr @printBYTE') then // jsr @printBYTE ; 1
221232
if (pos(' :STACKORIGIN,x', listing[i]) > 0 ) then
222233
begin
223-
224234
listing[i] := #9'lda ' + GetString(i);
225235
listing[i+1] := #9'jsr @printBYTE._a';
226236

227237
if dex(i+2) then
228238
for p:=i-1 downto 0 do
229-
if jsr(p) then Break else
239+
if fail(p) then Break else
230240
if inx(p) then begin listing[i+2] := ''; listing[p] := ''; Break end;
231241

232242
exit(false);
@@ -248,7 +258,7 @@ begin
248258

249259
if dex(i+3) then
250260
for p:=i-1 downto 0 do
251-
if jsr(p) then Break else
261+
if fail(p) then Break else
252262
if inx(p) then begin listing[i+3] := ''; listing[p] := ''; Break end;
253263

254264
exit(false);
@@ -276,7 +286,7 @@ begin
276286

277287
if dex(i+5) then
278288
for p:=i-1 downto 0 do
279-
if jsr(p) then Break else
289+
if fail(p) then Break else
280290
if inx(p) then begin listing[i+5] := ''; listing[p] := ''; Break end;
281291

282292
exit(false);

0 commit comments

Comments
 (0)