-
Notifications
You must be signed in to change notification settings - Fork 2
/
LAMAlib-structured.inc
1661 lines (1584 loc) · 74.6 KB
/
LAMAlib-structured.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; macros for store/restore, if-else-endif, for-next, do-loop, and switch
; i.o.w structured programming in assembler
; part of LAMAlib
; by Wil 2021
; auxiliary defintions for long branches, basically a copy of macro package longbranch
; but with other names, since we don't know if the user will use the macro package
.macro longbeq Target
.if .match(Target, 0)
bne *+5
jmp Target
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
beq Target
.else
bne *+5
jmp Target
.endif
.endmacro
.macro longbne Target
.if .match(Target, 0)
beq *+5
jmp Target
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
bne Target
.else
beq *+5
jmp Target
.endif
.endmacro
.macro longbmi Target
.if .match(Target, 0)
bpl *+5
jmp Target
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
bmi Target
.else
bpl *+5
jmp Target
.endif
.endmacro
.macro longbpl Target
.if .match(Target, 0)
bmi *+5
jmp Target
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
bpl Target
.else
bmi *+5
jmp Target
.endif
.endmacro
.macro longbcs Target
.if .match(Target, 0)
bcc *+5
jmp Target
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
bcs Target
.else
bcc *+5
jmp Target
.endif
.endmacro
.macro longbcc Target
.if .match(Target, 0)
bcs *+5
jmp Target
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
bcc Target
.else
bcs *+5
jmp Target
.endif
.endmacro
.macro longbvs Target
.if .match(Target, 0)
bvc *+5
jmp Target
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
bvs Target
.else
bvc *+5
jmp Target
.endif
.endmacro
.macro longbvc Target
.if .match(Target, 0)
bvs *+5
jmp Target
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
bvc Target
.else
bvs *+5
jmp Target
.endif
.endmacro
; auxiliary functions for generating labels for nested function
.macro inc_nesting_level
.if .defined(::nesting_level)
::nesting_level .set ::nesting_level*10
.if ::nesting_level = 90
::nesting_level .set ::nesting_level*10
.endif
.else
::nesting_level .set 10
.endif
.endmacro
.macro dec_nesting_level
::nesting_level .set ::nesting_level/10 + 1
.endmacro
;inc_nesting_levelA, inc_nesting_levelX and inc_nesting_levelY are used for store/restore
.macro inc_nesting_levelA
.if .defined(::nesting_levelA)
::nesting_levelA .set ::nesting_levelA*10
.else
::nesting_levelA .set 10
.endif
.endmacro
.macro dec_nesting_levelA
::nesting_levelA .set ::nesting_levelA/10 + 1
.endmacro
.macro inc_nesting_levelX
.if .defined(::nesting_levelX)
::nesting_levelX .set ::nesting_levelX*10
.else
::nesting_levelX .set 10
.endif
.endmacro
.macro dec_nesting_levelX
::nesting_levelX .set ::nesting_levelX/10 + 1
.endmacro
.macro inc_nesting_levelY
.if .defined(::nesting_levelY)
::nesting_levelY .set ::nesting_levelY*10
.else
::nesting_levelY .set 10
.endif
.endmacro
.macro dec_nesting_levelY
::nesting_levelY .set ::nesting_levelY/10 + 1
.endmacro
; the do_every macro uses a separate nesting_level counter
.macro inc_nesting_level_every
.if .defined(::nesting_level_every)
::nesting_level_every .set ::nesting_level_every*100
.else
::nesting_level_every .set 100
.endif
.endmacro
.macro dec_nesting_level_every
::nesting_level_every .set ::nesting_level_every/100 + 1
.endmacro
; the switch case macro uses a separate nesting_level counter
.macro inc_nesting_level_case
.if .defined(::nesting_level_case)
::nesting_level_case .set ::nesting_level_case*100
.else
::nesting_level_case .set 100
.endif
.endmacro
.macro dec_nesting_level_case
::nesting_level_case .set ::nesting_level_case/100 + 1
.endmacro
; the if function is using its own nesting level
.macro inc_nesting_level_if
.if .defined(::nesting_level_if)
::nesting_level_if .set ::nesting_level_if*10
.if ::nesting_level_if = 90
::nesting_level_if .set ::nesting_level_if*10
.endif
.else
::nesting_level_if .set 10
.endif
.endmacro
.macro dec_nesting_level_if
::nesting_level_if .set ::nesting_level_if/10 + 1
.endmacro
;; <h2>Structured Programming</h2>
;; These commands allow you to use constructs like <i>if .. else .. endif</i>, <i>do...loop</i>, <i>for...next</i>, and <i>switch...case</i> in assembly language! The structures can even be nested. The implementation of these structures is basically as efficient as a a handcoded composure of branches, jumps as labels, while it is much easier to write and read.
;; All macros can be nested.
;; store reg
;; Generates self-modifying code for store/restore of a register
;; Registers can be A,X,Y, or AX (that is A and X)
;; An example application for <i>store</i>/<i>restore</i> is for saving a register to be able use it in between. An alternative to <i>store</i>/<i>restore</i> are stack push/pull, which is more compact, but 1 cycle slower.
;; Each store must match with exactly one <i>restore</i> macro using the same register, restore has to be placed later in your code
;; inbetween store and restore, the stored value can be also accessed via address stored_A, stored_X, or stored_Y. Note that a stored AX is just a stored A and a stored X. The two addresses stored_A and stored_X are not consecutive.
;; Registers modified: none
.macro store reg
.if .xmatch ({reg}, {A})
inc_nesting_levelA
sta .ident(.sprintf("selfmod_A%d", ::nesting_levelA/10))+1
.elseif .xmatch ({reg}, {X})
inc_nesting_levelX
stx .ident(.sprintf("selfmod_X%d", ::nesting_levelX/10))+1
.elseif .xmatch ({reg}, {Y})
inc_nesting_levelY
sty .ident(.sprintf("selfmod_Y%d", ::nesting_levelY/10))+1
.elseif .xmatch({reg}, {AX}) .or .xmatch ({reg}, {ax})
store A
store X
.endif
.endmacro
.define stored_A .ident(.sprintf("selfmod_A%d", ::nesting_levelA/10))+1
.define stored_X .ident(.sprintf("selfmod_X%d", ::nesting_levelX/10))+1
.define stored_Y .ident(.sprintf("selfmod_Y%d", ::nesting_levelY/10))+1
;; restore reg
;; Generates the code for restoreing a stored register
;; Registers can be A,X,Y, or AX (that is A and X)
;; Each restore must match with exactly one preceding <i>store</i> macro using the same register
;; Registers modified: the restoreed register
.macro restore reg
.if .xmatch ({reg}, {A})
.ident(.sprintf("selfmod_A%d", ::nesting_levelA/10)):
lda #00
dec_nesting_levelA
.elseif .xmatch ({reg}, {X})
.ident(.sprintf("selfmod_X%d", ::nesting_levelX/10)):
ldx #00
dec_nesting_levelX
.elseif .xmatch ({reg}, {Y})
.ident(.sprintf("selfmod_Y%d", ::nesting_levelY/10)):
ldy #00
dec_nesting_levelY
.elseif .xmatch({reg}, {AX}) .or .xmatch ({reg}, {ax})
restore A
restore X
.endif
.endmacro
;; if cond
;; <b>longif</b> cond
;; <b>if_A_in</b> arg1,arg2,...
;; <b>if_X_in</b> arg1,arg2,...
;; <b>if_Y_in</b> arg1,arg2,...
;; ...
;; [<b>else</b>]
;; ...
;; <b>endif</b>
;; This is a structure for conditional execution
;; <i>cond</i> can be <i>eq</i>, <i>ne</i>, <i>mi</i>, <i>pl</i>, <i>cc</i>, <i>cs</i>, <i>vc</i>, <i>vs</i>, <i>lt</i>, <i>ge</i>
;; This corresponds to assembler commands BEQ, BNE, BMI, BPL, BCC, BCS, BVC, BVS
;; Therefore the amount of code between if and else must not exceed the range of a branch instruction (127 byte for a forward branch)
;; <i>lt</i> (less than) is equal to <i>cc</i> (BCC), <i>ge</i> (greater or equal) is equal to <i>cs</i> (BCS)
;; using else is optional
;; <i>longif</i> is doing the same as <i>if</i>, but it is using long branches
;; <i>if_A_in arg1,arg2,...</i> triggers if A (or, respectively, X,Y) is equal to any value (immediate or address) in the list
;; Registers modified: none
.macro if cond
inc_nesting_level_if
.if ((.xmatch ({cond}, {eq})) || (.xmatch ({cond}, {zero})))
bne .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
.elseif (.xmatch ({cond}, {ne}))
beq .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
.elseif (.xmatch ({cond}, {mi}))
bpl .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
.elseif (.xmatch ({cond}, {pl}))
bmi .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
.elseif ((.xmatch ({cond}, {cc})) || (.xmatch ({cond}, {lt})))
bcs .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
.elseif ((.xmatch ({cond}, {cs})) || (.xmatch ({cond}, {ge})))
bcc .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
.elseif (.xmatch ({cond}, {vc}))
bvs .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
.elseif (.xmatch ({cond}, {vs}))
bvc .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
.else
.error "Condition for if undefined!"
.endif
.endmacro
.macro if_A_in arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9
.ifnblank arg1
.if (.match (.left (1, {arg1}), #))
; explicitly stated immediate mode
cmp arg1
.else
cmp #arg1
.endif
beq :+
if_A_in arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9
.else
inc_nesting_level_if
jmp .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
:
.endif
.endmacro
.macro if_X_in arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9
.ifnblank arg1
.if (.match (.left (1, {arg1}), #))
; explicitly stated immediate mode
cpx arg1
.else
cpx #arg1
.endif
beq :+
if_X_in arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9
.else
inc_nesting_level_if
jmp .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
:
.endif
.endmacro
.macro if_Y_in arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9
.ifnblank arg1
.if (.match (.left (1, {arg1}), #))
; explicitly stated immediate mode
cpy arg1
.else
cpy #arg1
.endif
beq :+
if_Y_in arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9
.else
inc_nesting_level_if
jmp .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
:
.endif
.endmacro
.macro longif cond
inc_nesting_level_if
.if ((.xmatch ({cond}, {eq})) || (.xmatch ({cond}, {zero})))
longbne .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
.elseif (.xmatch ({cond}, {ne}))
longbeq .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
.elseif (.xmatch ({cond}, {mi}))
longbpl .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
.elseif (.xmatch ({cond}, {pl}))
longbmi .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
.elseif ((.xmatch ({cond}, {cc})) || (.xmatch ({cond}, {lt})))
longbcs .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
.elseif ((.xmatch ({cond}, {cs})) || (.xmatch ({cond}, {ge})))
longbcc .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
.elseif (.xmatch ({cond}, {vc}))
longbvs .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
.elseif (.xmatch ({cond}, {vs}))
longbvc .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
.else
.error "Condition for if undefined!"
.endif
.endmacro
.macro else
jmp .ident(.sprintf("end_of_if%d", ::nesting_level_if/10))
.ident(.sprintf("else_or_end%d", ::nesting_level_if/10)):
.endmacro
.macro endif
.ifndef .ident(.sprintf("else_or_end%d", ::nesting_level_if/10))
.ident(.sprintf("else_or_end%d", ::nesting_level_if/10)):
.endif
.ident(.sprintf("end_of_if%d", ::nesting_level_if/10)):
dec_nesting_level_if
.endmacro
;; for </i><b>X|Y|A|AX</b><i>|addr,start,</i><b>to|downto</b><i>,end,step
;; ...
;; <b>next</b>
;; The for loop iterates from the start value to the end value, inclusive. This is similar to the behavior of FOR in BASIC
;; Counting variable can be an 8-bit register (A,X,Y), a 16 bit register (AX) or a 16 bit memory address/label (parentheses are optional)
;; <i>start</i> can be a constant or a memory address pointing to the value; (xxx) indicates a 16 bit value at address xxx and xxx+1, [xxx] indicates an 8 bit value at adress xxx
;; <i>end</i> can be a constant or a memory address pointing to the value. The loop is continued including an iteration reaching the <i>end</i> value
;; <i>start</i> can be a constant or a memory address pointing to the value
;; <b>to</b> indicates a loop that counts up, <b>downto</b> indicates a loop that counts down
;; <i>end</i> can be a constant or a memory address pointing to the value
;; <b>step</b> is optional and defines the increment/decrement (default=1). This value is alway positive, counting down is indicated with <b>downto</b>
;;
;; When the loop variable is an 8 bit register or a memory address in square brackets, <i>start</i>, <i>end</i>, and <i>step</i> are a single byte (or a memory reference to a single byte)
;; When the loop variable is a 16 bit register (AX) or a 16 bit memory address, <i>start</i>, <i>end</i>, and <i>step</i> are a 16 bit value (or a memory reference to a 16 bit value)
;; Memory references can also go to zero page. In this case the zero page addressing mode is used which speeds up the code.
;; When <i>step</i> is larger than 1 or no constant, loops that count down can are limited to a 7 bit (for single register loops) or a 15 bit range
;; It is possible to nest multiple for loops but each <b>for</b> must be followed by exactly one corresponding <i>next</i> later in the code.
;;
;; Within a for loop, the macros <i>break</i> and <i>continue</i> can be used to exit the loop or go to next iteration.
;;
;; Registers modified: the loop register and A for indirectly given step values
;;
;; Code example that outputs '9876543210':
;; <code>
;; for A,$39,downto,$30
;; jsr $ffd2
;; next
;; </code>
.macro for var,start,dir,end,step
inc_nesting_level
.if .xmatch ({var}, {A})
.ident(.sprintf("for_var%d", ::nesting_level/10))=-1
.elseif .xmatch ({var}, {X})
.ident(.sprintf("for_var%d", ::nesting_level/10))=-2
.elseif .xmatch ({var}, {Y})
.ident(.sprintf("for_var%d", ::nesting_level/10))=-3
.elseif .xmatch ({var}, {AX}) .or .xmatch ({var}, {ax})
.ident(.sprintf("for_var%d", ::nesting_level/10))=-4
.elseif (.match (.left (1, {var}), {(})) .and (.match (.right (1, {var}), {)}))
.ident(.sprintf("for_var%d", ::nesting_level/10))=-5
.ident(.sprintf("for_var_addr%d", ::nesting_level/10))=var
.else
.ident(.sprintf("for_var%d", ::nesting_level/10))=-6
.ident(.sprintf("for_var_addr%d", ::nesting_level/10))=.mid(1,.tcount(var)-2, var)
.endif
.if .xmatch ({dir}, {to}) || .xmatch ({dir}, {TO})
.ident(.sprintf("for_dir%d", ::nesting_level/10))=1
.elseif .xmatch ({dir}, {downto}) || .xmatch ({dir}, {DOWNTO})
.ident(.sprintf("for_dir%d", ::nesting_level/10))=-1
.else
.error "Syntax error in for loop, 3rd argument needs to be 'to' or 'downto'!"
.endif
.if .paramcount = 5
.ident(.sprintf("for_inc%d", ::nesting_level/10))=step
.if (.match (.left (1, {step}), {(})) .and (.match (.right (1, {step}), {)})) ;argument in brackets -> means indirect addressing
.ident(.sprintf("for_inc%d_indirect", ::nesting_level/10))=1
.else
.ident(.sprintf("for_inc%d_indirect", ::nesting_level/10))=0
.endif
.else
.ident(.sprintf("for_inc%d", ::nesting_level/10)) .set 1
.ident(.sprintf("for_inc%d_indirect", ::nesting_level/10))=0
.endif
.if (.match (.left (1, {end}), {(})) .and (.match (.right (1, {end}), {)})) ;argument in brackets -> means indirect addressing
.ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
.ident(.sprintf("for_end%d", ::nesting_level/10))=end
.else
.ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=0
.if .ident(.sprintf("for_dir%d", ::nesting_level/10))>0
.ident(.sprintf("for_end%d", ::nesting_level/10))=end+1
.else
.ident(.sprintf("for_end%d", ::nesting_level/10))=end-1
.endif
.endif
.if (.match (.left (1, {start}), {(})) .and (.match (.right (1, {start}), {)})) ;argument in brackets -> means indirect addressing
.ident(.sprintf("for_start%d_indirect", ::nesting_level/10))=1
.ident(.sprintf("for_start_positive%d", ::nesting_level/10))=0
.if .ident(.sprintf("for_var%d", ::nesting_level/10))=-2
ldx 0+start
.elseif .ident(.sprintf("for_var%d", ::nesting_level/10))=-3
ldy 0+start
.elseif .ident(.sprintf("for_var%d", ::nesting_level/10))=-1
lda 0+start
.elseif .ident(.sprintf("for_var%d", ::nesting_level/10))=-4
ldax 0+start
.elseif .ident(.sprintf("for_var%d", ::nesting_level/10))=-5
lda 0+start
sta .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
lda 0+start+1
sta .ident(.sprintf("for_var_addr%d", ::nesting_level/10))+1
.else
lda 0+start
sta .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
.endif
.else
.ident(.sprintf("for_start%d_indirect", ::nesting_level/10))=0
.if .ident(.sprintf("for_var%d", ::nesting_level/10))=-2
ldx #start
.if start<128
.ident(.sprintf("for_start_positive%d", ::nesting_level/10))=1
.else
.ident(.sprintf("for_start_positive%d", ::nesting_level/10))=0
.endif
.elseif .ident(.sprintf("for_var%d", ::nesting_level/10))=-3
ldy #start
.if start<128
.ident(.sprintf("for_start_positive%d", ::nesting_level/10))=1
.else
.ident(.sprintf("for_start_positive%d", ::nesting_level/10))=0
.endif
.elseif .ident(.sprintf("for_var%d", ::nesting_level/10))=-1
lda #start
.if start<128
.ident(.sprintf("for_start_positive%d", ::nesting_level/10))=1
.else
.ident(.sprintf("for_start_positive%d", ::nesting_level/10))=0
.endif
.elseif .ident(.sprintf("for_var%d", ::nesting_level/10))=-4
ldax #start
.ident(.sprintf("for_start%d", ::nesting_level/10))=start
.if start<32768
.ident(.sprintf("for_start_positive%d", ::nesting_level/10))=1
.else
.ident(.sprintf("for_start_positive%d", ::nesting_level/10))=0
.endif
.elseif .ident(.sprintf("for_var%d", ::nesting_level/10))=-5
.if start<32768
.ident(.sprintf("for_start_positive%d", ::nesting_level/10))=1
.else
.ident(.sprintf("for_start_positive%d", ::nesting_level/10))=0
.endif
lda #<(start)
sta .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
lda #>(start)
sta .ident(.sprintf("for_var_addr%d", ::nesting_level/10))+1
.else
.if start<128
.ident(.sprintf("for_start_positive%d", ::nesting_level/10))=1
.else
.ident(.sprintf("for_start_positive%d", ::nesting_level/10))=0
.endif
lda #(start)
sta .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
.endif
.endif
.ident(.sprintf("begin_loop%d", ::nesting_level/10)):
.endmacro
.macro next
.if .paramcount = 1
.if .xmatch ({cond}, {:}) ;user tried to make a label
.proc next ;trick assembler into creating a label named loop instead of expanding the loop macro
.endproc ;close proc, we just needed it for the label
.exitmacro
.endif
.endif
.ident(.sprintf("continue_point%d", ::nesting_level/10)):
.if .ident(.sprintf("for_dir%d", ::nesting_level/10))>0 ;--- incrementing loops ---
.if .ident(.sprintf("for_var%d", ::nesting_level/10))=-2 ;--- next X ---
.if .ident(.sprintf("for_inc%d_indirect", ::nesting_level/10))=1
txa
clc
adc .ident(.sprintf("for_inc%d", ::nesting_level/10))
tax
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
cpx .ident(.sprintf("for_end%d", ::nesting_level/10))
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
longbeq .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
cpx #.ident(.sprintf("for_end%d", ::nesting_level/10))
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.else
.if .ident(.sprintf("for_inc%d", ::nesting_level/10)) > 5
txa
clc
adc #.ident(.sprintf("for_inc%d", ::nesting_level/10))
tax
.else
.repeat .ident(.sprintf("for_inc%d", ::nesting_level/10))
inx
.endrep
.endif
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
cpx .ident(.sprintf("for_end%d", ::nesting_level/10))
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
longbeq .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
.if .ident(.sprintf("for_inc%d", ::nesting_level/10))=1
.if .not <.ident(.sprintf("for_end%d", ::nesting_level/10))=0
cpx #<.ident(.sprintf("for_end%d", ::nesting_level/10))
.endif
longbne .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
cpx #.ident(.sprintf("for_end%d", ::nesting_level/10))
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.endif
.endif
.elseif .ident(.sprintf("for_var%d", ::nesting_level/10))=-3 ;--- next Y ---
.if .ident(.sprintf("for_inc%d_indirect", ::nesting_level/10))=1
tya
clc
adc .ident(.sprintf("for_inc%d", ::nesting_level/10))
tay
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
cpy .ident(.sprintf("for_end%d", ::nesting_level/10))
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
longbeq .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
cpy #.ident(.sprintf("for_end%d", ::nesting_level/10))
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.else
.if .ident(.sprintf("for_inc%d", ::nesting_level/10)) > 5
tya
clc
adc #.ident(.sprintf("for_inc%d", ::nesting_level/10))
tay
.else
.repeat .ident(.sprintf("for_inc%d", ::nesting_level/10))
iny
.endrep
.endif
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
cpy .ident(.sprintf("for_end%d", ::nesting_level/10))
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
longbeq .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
.if .ident(.sprintf("for_inc%d", ::nesting_level/10))=1
.if .not <.ident(.sprintf("for_end%d", ::nesting_level/10))=0
cpy #<.ident(.sprintf("for_end%d", ::nesting_level/10))
.endif
longbne .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
cpy #.ident(.sprintf("for_end%d", ::nesting_level/10))
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.endif
.endif
.elseif .ident(.sprintf("for_var%d", ::nesting_level/10))=-1 ;--- next A ---
.if .ident(.sprintf("for_inc%d_indirect", ::nesting_level/10))=1
clc
adc .ident(.sprintf("for_inc%d", ::nesting_level/10))
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
cmp .ident(.sprintf("for_end%d", ::nesting_level/10))
.if ((*+4)-(.ident(.sprintf("begin_loop%d", ::nesting_level/10))) <= 127)
bcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
beq .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
bcs *+5
jmp .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.else
cmp #.ident(.sprintf("for_end%d", ::nesting_level/10))
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.else
clc
adc #.ident(.sprintf("for_inc%d", ::nesting_level/10))
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
cmp .ident(.sprintf("for_end%d", ::nesting_level/10))
.if ((*+4)-(.ident(.sprintf("begin_loop%d", ::nesting_level/10))) <= 127)
bcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
beq .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
bcs *+5
jmp .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.else
.if .ident(.sprintf("for_inc%d", ::nesting_level/10))=1
.if .not <.ident(.sprintf("for_end%d", ::nesting_level/10))=0
cmp #<.ident(.sprintf("for_end%d", ::nesting_level/10))
.endif
longbne .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
cmp #.ident(.sprintf("for_end%d", ::nesting_level/10))
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.endif
.endif
.elseif .ident(.sprintf("for_var%d", ::nesting_level/10))=-4 ;--- next AX ---
.if .ident(.sprintf("for_inc%d_indirect", ::nesting_level/10))=1
clc
adcax .ident(.sprintf("for_inc%d", ::nesting_level/10))
.else
.if .ident(.sprintf("for_inc%d", ::nesting_level/10))=1
incax
.else
clc
adcax #.ident(.sprintf("for_inc%d", ::nesting_level/10))
.endif
.endif
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
cpx .ident(.sprintf("for_end%d", ::nesting_level/10))+1
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
cmp .ident(.sprintf("for_end%d", ::nesting_level/10))
.if ((*+4)-(.ident(.sprintf("begin_loop%d", ::nesting_level/10))) <= 127)
bcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
beq .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
bcs *+5
jmp .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.else
.if .ident(.sprintf("for_start%d_indirect", ::nesting_level/10))=1
cpx #>.ident(.sprintf("for_end%d", ::nesting_level/10))
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.elseif (>.ident(.sprintf("for_start%d", ::nesting_level/10))) <> (>.ident(.sprintf("for_end%d", ::nesting_level/10)))
cpx #>.ident(.sprintf("for_end%d", ::nesting_level/10))
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
cmp #<.ident(.sprintf("for_end%d", ::nesting_level/10))
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.elseif .ident(.sprintf("for_var%d", ::nesting_level/10))=-4 ;--- next (addr) ---
.if .ident(.sprintf("for_inc%d_indirect", ::nesting_level/10))=1
lda .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
clc
adc .ident(.sprintf("for_inc%d", ::nesting_level/10))
sta .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
lda .ident(.sprintf("for_var_addr%d", ::nesting_level/10))+1
adc .ident(.sprintf("for_inc%d", ::nesting_level/10))+1
sta .ident(.sprintf("for_var_addr%d", ::nesting_level/10))+1
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
cmp .ident(.sprintf("for_end%d", ::nesting_level/10))+1
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
bne .ident(.sprintf("end_loop%d", ::nesting_level/10))
lda .ident(.sprintf("for_end%d", ::nesting_level/10))
cmp .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
longbcs .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
cmp #>.ident(.sprintf("for_end%d", ::nesting_level/10))
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
bne .ident(.sprintf("end_loop%d", ::nesting_level/10))
lda .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
cmp #<.ident(.sprintf("for_end%d", ::nesting_level/10))
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.else
.if .ident(.sprintf("for_inc%d", ::nesting_level/10))=1
inc16 .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
lda .ident(.sprintf("for_var_addr%d", ::nesting_level/10))+1
cmp .ident(.sprintf("for_end%d", ::nesting_level/10))+1
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
lda .ident(.sprintf("for_end%d", ::nesting_level/10))
cmp .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
longbcs .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
lda .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
.if (<.ident(.sprintf("for_end%d", ::nesting_level/10)))>0
cmp #<.ident(.sprintf("for_end%d", ::nesting_level/10))
.endif
longbne .ident(.sprintf("begin_loop%d", ::nesting_level/10))
lda .ident(.sprintf("for_var_addr%d", ::nesting_level/10))+1
.if (>.ident(.sprintf("for_end%d", ::nesting_level/10)))>0
cmp #>.ident(.sprintf("for_end%d", ::nesting_level/10))
.endif
longbne .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.else
lda .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
clc
adc #<.ident(.sprintf("for_inc%d", ::nesting_level/10))
sta .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
lda .ident(.sprintf("for_var_addr%d", ::nesting_level/10))+1
adc #>.ident(.sprintf("for_inc%d", ::nesting_level/10))
sta .ident(.sprintf("for_var_addr%d", ::nesting_level/10))+1
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
cmp .ident(.sprintf("for_end%d", ::nesting_level/10))+1
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
bne .ident(.sprintf("end_loop%d", ::nesting_level/10))
lda .ident(.sprintf("for_end%d", ::nesting_level/10))
cmp .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
longbcs .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
cmp #>.ident(.sprintf("for_end%d", ::nesting_level/10))
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
bne .ident(.sprintf("end_loop%d", ::nesting_level/10))
lda .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
cmp #<.ident(.sprintf("for_end%d", ::nesting_level/10))
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.endif
.endif
.else ;--- next [addr] ---
.if .ident(.sprintf("for_inc%d_indirect", ::nesting_level/10))=1
lda .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
clc
adc .ident(.sprintf("for_inc%d", ::nesting_level/10))
sta .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
cmp .ident(.sprintf("for_end%d", ::nesting_level/10))
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
longbeq .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
cmp #.ident(.sprintf("for_end%d", ::nesting_level/10))
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.else ;for_inc given as number
.if .ident(.sprintf("for_inc%d", ::nesting_level/10))=1
inc .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
lda .ident(.sprintf("for_end%d", ::nesting_level/10))
cmp .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
.else
lda .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
cmp #.ident(.sprintf("for_end%d", ::nesting_level/10))
.endif
longbne .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
lda .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
clc
adc #.ident(.sprintf("for_inc%d", ::nesting_level/10))
sta .ident(.sprintf("for_var_addr%d", ::nesting_level/10))
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
cmp .ident(.sprintf("for_end%d", ::nesting_level/10))
.else
cmp #.ident(.sprintf("for_end%d", ::nesting_level/10))
.endif
longbcc .ident(.sprintf("begin_loop%d", ::nesting_level/10))
longbeq .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.endif
.endif
.else ;--- decrementing loops ---
.if .ident(.sprintf("for_var%d", ::nesting_level/10))=-2 ;--- next X ---
.if .ident(.sprintf("for_inc%d_indirect", ::nesting_level/10))=1
txa
sec
sbc .ident(.sprintf("for_inc%d", ::nesting_level/10))
tax
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
cpx .ident(.sprintf("for_end%d", ::nesting_level/10))
longbpl .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
.if .ident(.sprintf("for_end%d", ::nesting_level/10)) >= 0
cpx #.ident(.sprintf("for_end%d", ::nesting_level/10))+1
.endif
longbpl .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.else
.if .ident(.sprintf("for_inc%d", ::nesting_level/10)) > 5
txa
sec
sbc #.ident(.sprintf("for_inc%d", ::nesting_level/10))
tax
.else
.repeat .ident(.sprintf("for_inc%d", ::nesting_level/10))
dex
.endrep
.endif
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
cpx .ident(.sprintf("for_end%d", ::nesting_level/10))
longbpl .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
.if .ident(.sprintf("for_inc%d", ::nesting_level/10))=1
.if .ident(.sprintf("for_end%d", ::nesting_level/10)) = -1
.if .ident(.sprintf("for_start_positive%d", ::nesting_level/10))=1
longbpl .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
cpx #.ident(.sprintf("for_end%d", ::nesting_level/10))+$100
longbne .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.else
.if .ident(.sprintf("for_end%d", ::nesting_level/10)) > 0
cpx #.ident(.sprintf("for_end%d", ::nesting_level/10))
.endif
longbne .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.else
.if .ident(.sprintf("for_end%d", ::nesting_level/10))-.ident(.sprintf("for_inc%d", ::nesting_level/10)) < 0
.if .ident(.sprintf("for_start_positive%d", ::nesting_level/10))=1
longbmi .ident(.sprintf("end_loop%d", ::nesting_level/10))
.else
cpx #.ident(.sprintf("for_end%d", ::nesting_level/10))-.ident(.sprintf("for_inc%d", ::nesting_level/10))+$100
longbcs .ident(.sprintf("end_loop%d", ::nesting_level/10))
.endif
.endif
.if .ident(.sprintf("for_end%d", ::nesting_level/10)) < 0
jmp .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.elseif .ident(.sprintf("for_end%d", ::nesting_level/10)) > 0
cpx #.ident(.sprintf("for_end%d", ::nesting_level/10))+1
longbcs .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
longbne .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.endif
.endif
.endif
.elseif .ident(.sprintf("for_var%d", ::nesting_level/10))=-3 ;--- next Y ---
.if .ident(.sprintf("for_inc%d_indirect", ::nesting_level/10))=1
tya
sec
sbc .ident(.sprintf("for_inc%d", ::nesting_level/10))
tay
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
cpy .ident(.sprintf("for_end%d", ::nesting_level/10))
longbpl .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
.if .ident(.sprintf("for_end%d", ::nesting_level/10)) >= 0
cpy #.ident(.sprintf("for_end%d", ::nesting_level/10))+1
.endif
longbpl .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.else
.if .ident(.sprintf("for_inc%d", ::nesting_level/10)) > 5
tya
sec
sbc #.ident(.sprintf("for_inc%d", ::nesting_level/10))
tay
.else
.repeat .ident(.sprintf("for_inc%d", ::nesting_level/10))
dey
.endrep
.endif
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
cpy .ident(.sprintf("for_end%d", ::nesting_level/10))
longbpl .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
.if .ident(.sprintf("for_inc%d", ::nesting_level/10))=1
.if .ident(.sprintf("for_end%d", ::nesting_level/10)) = -1
.if .ident(.sprintf("for_start_positive%d", ::nesting_level/10))=1
longbpl .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
cpy #.ident(.sprintf("for_end%d", ::nesting_level/10))+$100
longbne .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.else
.if .ident(.sprintf("for_end%d", ::nesting_level/10)) > 0
cpy #.ident(.sprintf("for_end%d", ::nesting_level/10))
.endif
longbne .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.else
.if .ident(.sprintf("for_end%d", ::nesting_level/10))-.ident(.sprintf("for_inc%d", ::nesting_level/10)) < 0
.if .ident(.sprintf("for_start_positive%d", ::nesting_level/10))=1
bmi .ident(.sprintf("end_loop%d", ::nesting_level/10))
.else
cpy #.ident(.sprintf("for_end%d", ::nesting_level/10))-.ident(.sprintf("for_inc%d", ::nesting_level/10))+$100
bcs .ident(.sprintf("end_loop%d", ::nesting_level/10))
.endif
.endif
.if .ident(.sprintf("for_end%d", ::nesting_level/10)) < 0
jmp .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.elseif .ident(.sprintf("for_end%d", ::nesting_level/10)) > 0
cpy #.ident(.sprintf("for_end%d", ::nesting_level/10))+1
longbcs .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
longbne .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.endif
.endif
.endif
.elseif .ident(.sprintf("for_var%d", ::nesting_level/10))=-1 ;--- next A ---
.if .ident(.sprintf("for_inc%d_indirect", ::nesting_level/10))=1
sec
sbc .ident(.sprintf("for_inc%d", ::nesting_level/10))
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
cmp .ident(.sprintf("for_end%d", ::nesting_level/10))
longbpl .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
.if .ident(.sprintf("for_end%d", ::nesting_level/10)) >= 0
cmp #.ident(.sprintf("for_end%d", ::nesting_level/10))+1
.endif
longbpl .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.else
sec
sbc #.ident(.sprintf("for_inc%d", ::nesting_level/10))
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1
cmp .ident(.sprintf("for_end%d", ::nesting_level/10))
longbpl .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
.if .ident(.sprintf("for_inc%d", ::nesting_level/10))=1
.if .ident(.sprintf("for_end%d", ::nesting_level/10)) = -1
.if .ident(.sprintf("for_start_positive%d", ::nesting_level/10))=1
longbpl .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
cmp #.ident(.sprintf("for_end%d", ::nesting_level/10))+$100
longbne .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.else
.if .ident(.sprintf("for_end%d", ::nesting_level/10)) > 0
cmp #.ident(.sprintf("for_end%d", ::nesting_level/10))
.endif
longbne .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.else
.if .ident(.sprintf("for_end%d", ::nesting_level/10))-.ident(.sprintf("for_inc%d", ::nesting_level/10)) < 0
.if .ident(.sprintf("for_start_positive%d", ::nesting_level/10))=1
bmi .ident(.sprintf("end_loop%d", ::nesting_level/10))
.else
cmp #.ident(.sprintf("for_end%d", ::nesting_level/10))-.ident(.sprintf("for_inc%d", ::nesting_level/10))+$100
bcs .ident(.sprintf("end_loop%d", ::nesting_level/10))
.endif
.endif
.if .ident(.sprintf("for_end%d", ::nesting_level/10)) < 0
jmp .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.elseif .ident(.sprintf("for_end%d", ::nesting_level/10)) > 0
cmp #.ident(.sprintf("for_end%d", ::nesting_level/10))+1
longbcs .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.else
longbne .ident(.sprintf("begin_loop%d", ::nesting_level/10))
.endif
.endif
.endif
.endif
.elseif .ident(.sprintf("for_var%d", ::nesting_level/10))=-4 ;--- next AX ---
.if .ident(.sprintf("for_inc%d_indirect", ::nesting_level/10))=1
sec
sbcax .ident(.sprintf("for_inc%d", ::nesting_level/10))
.if .ident(.sprintf("for_end%d_indirect", ::nesting_level/10))=1