-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathdoloop.src
165 lines (141 loc) · 2.38 KB
/
doloop.src
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
.page
.subttl DO / LOOP Commands
do ldy #1
1$ lda txtptr,y ;save current pointers for stack entry
sta tmptxt,y
lda curlin,y
sta tmplin,y
dey
bpl 1$
jsr chrgot ;look for 'while' or 'until'
beq doyes ;unconditional
cmp #untltk
beq do10
cmp #whiltk
bne snrjmp
;
; here for 'while'
;
jsr frmjmp
lda facexp
bne doyes ;conditional evaluated true
dono jsr chrgot
jmp fnd010 ;advance to end of block, do rts
;
; here for 'until'
;
do10 jsr frmjmp
lda facexp
bne dono
doyes lda #5 ;'do' needs 5 bytes on the run-time stack
jsr getstk
sta sw_rom_ram0
ldy #4 ;..now stuff those 5 bytes!
lda tmptxt+1
sta (tos),y
dey
lda tmptxt
sta (tos),y
dey
lda tmplin+1
sta (tos),y
dey
lda tmplin
sta (tos),y
dey
lda #dotk
sta (tos),y
rts
exit jsr popdgo ;pop do entry off stack
jsr chrgot
beq fnd010
snrjmp jmp snerr
; find end of current block
;
fndend
jsr chrget
fnd010
beq fnd50 ;end of statement
cmp #looptk
beq fnd60 ;a hit!
cmp #'"' ;quote
beq fnd40
cmp #dotk
bne fndend ;keep looking
jsr fndend ;recursivly
jmp dono ;do a chrgot,go to fnd010
fnd40 jsr un_quote ;look for terminating quote, or end of statement
bne fndend ;character after quote wasn't terminator, keep going
fnd50 cmp #':' ;end of line or end of stmt?
beq fndend ;just stmt, keep going
bit runmod ;direct mode?
bpl fnderr ;yes, so not found
ldy #2
jsr indtxt ;end of text?
beq fnderr ;'fraid so
iny ;y=3
jsr indtxt ;update pointers
sta curlin
iny
jsr indtxt
sta curlin+1
tya
clc
adc txtptr
sta txtptr
bcc fndend
inc txtptr+1
bne fndend
fnd60 jmp data ;read to end of statement,rts
.page
loop beq popngo ;no conditionals, just do it
cmp #whiltk
beq loop10
cmp #untltk
bne snrjmp
;
; here for 'until'
;
jsr frmjmp
lda facexp
beq popngo ;false, do it again!
popdgo lda #dotk ;pop, but don't go
jsr search
bne poperr ;branch if not found
jsr movfnd
ldy #5
jmp rlsstk
fnderr
lda tmplin ;loop not found error: must make curlin match oldtxt
ldx tmplin+1
sta curlin
stx curlin+1
ldx #errlnf
.byte $2c
poperr
ldx #errlwd ;loop without do
jmp error
;
; here for 'while'
;
loop10
jsr frmjmp
beq popdgo ;false, exit
popngo
jsr popdgo
dey
lda (fndpnt),y ;restore pointers
sta txtptr+1
dey
lda (fndpnt),y
sta txtptr
dey
lda (fndpnt),y
jsr retpat ;(** 01/18/84 fixes 'loop' to a direct mode 'do')
lda (fndpnt),y
sta curlin
jmp do
frmjmp
jsr chrget
jmp frmevl
;.end