-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcontrol words notes.txt
194 lines (167 loc) · 2.98 KB
/
control words notes.txt
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
http://forum.6502.org/viewtopic.php?f=9&t=3176
unloop becomes RTS?
pdo
lda #>(unloop-1)
pha
lda #<(unloop-1)
pha
unloop
pla
sta ip
pla
sta ip+1
jmp next
: do
[compile] (do) here 0 c, ; immediate
Rewritten code
pdo
jsr locals2
ldy #3
tya
adc (ip),y ; offset to past (loop)
adc ip
tay
lda ip+1
adc #0
pha
tya
pha
ldy #3
pdo01
lda zi,y
pha
lda tos,y
sta zi,y
dey
bpl pdo01
bne drop ; bra
FIG control words
: back
here - , ;
: begin
?comp here 1 ;
: endif
?comp 2 ?pairs here over - swap ! ;
: then
endif ;
: do
[compile] (do) here 3 ;
: loop
3 ?pairs [compile] (loop) back ;
: +loop
3 ?pairs [compile] (+loop) back ;
: until
1 ?pairs [compile] 0branch back ;
: end
until ;
: again
1 ?pairs [compile] branch back ;
: repeat
>r >r again r> r> 2 - endif ;
: if
[compile] 0branch here 0 , 2 ;
: else
2 ?pairs [compile] branch here 0 , swap 2 endif 2 ;
: while
if 2+ ;
IF
ELSE
THEN
DO
?do
LEAVE
?leave
LOOP
+LOOP
BEGIN
WHILE
UNTIL
AGAIN
REPEAT
: if
0 0 [compile] ?branch ?>mark 2 ; immediate
: else
2 ?pairs [compile] branch swap ?>mark swap ?>resolve 0 -2 ; immediate
: then
?comp abs 2 ?pairs ?>resolve ?>resolve ; immediate
: do
[ $fb ] literal ?page [compile] (do) ?<mark 3 ; immediate
: ?do
[ $fb ] literal ?page
[compile] (?do) 0 ?>mark ?<mark drop swap 3 ; immediate
: leave
[compile] (leave) 3 add>mark ;
: ?leave
[compile] (?leave) 3 add>mark ; immediate
: loop
3 ?pairs [ $fb ] cliteral ?page [compile] (loop) ?<resolve ; immediate
: +loop
3 ?pairs [compile] (+loop) ?<resolve ; immediate
: begin
?<mark 1 ; immediate
: while
[compile] ?branch 1 add>mark ; immediate
: until
1 ?pairs [compile] ?branch ?<resolve ; immediate
: again
1 ?pairs [compile] branch ?<resolve ; immediate
: repeat
again ; immediate
eighterase
ldy #7
.byt $2c ; BIT abs
fourerase
ldy #3
.byt $2c ; BIT abs
threeerase
ldy #2
lda #0
threeerase01
sta (tos),y
dey
bpl threeerase01
jmp drop
1 begin/while/until/again/repeat
2 if/else/then
3 do/loop
pairs
.dsb 3,0 ; storage for counters
_resetpairs
jsr enter
.word plit
.word pairs
.word threerase
.word exit
(pairs)
pluspairs
clc
.byt $29 ; AND immediate
minuspairs
sec
txa
ldx tos
bcs pairs01
inc pairs-1,x
inc pairs-1,x
pairs01
dec pairs-1,x
bmi pairs03
tax
ldy #6 ; UNPAIRED CONDITIONALS
pairs02
ldy #5 ; COMPILATION ONLY
lda uarea+userstate-userarea
beq pairs04
jmp drop
querypairs
ldy tos
lda pairs-1,y
bne pairs02 ; OKAY
pairs03
ldy #6 ; UNPAIRED CONDITIONALS
pairs04
jmp error
: if
0 0 [compile] ?branch ?>mark 2 +pairs ; immediate
else
2 ?pairs [compile] branch swap ?>mark swap ?>resolve 0 -2 ; immediate