comparison lib/alib/linedit.as @ 2783:03f26e88b809 lwtools-port

Renamed files and setup for lwasm/lwlink work
author Boisy Pitre <boisy.pitre@nuance.com>
date Sat, 26 Jan 2013 17:18:24 -0600
parents lib/alib/linedit.a@aaba193af04f
children
comparison
equal deleted inserted replaced
2782:aaba193af04f 2783:03f26e88b809
1 ***************************************
2
3 * Edit/input line.
4
5 * This routine does not use cursor positioning,
6 * instead it uses backspacing, etc. This means it
7 * can be used without a GOTOXY module, however it
8 * is a bit slow, especially when lines get longer than
9 * one line. If the buffer contains data, you will be
10 * able to edit; to enter new data pass a buffer of
11 * blanks.
12
13 * OTHER MODULES NEEDED: STRLEN,IS_PRINT, FPUTS, FPUTC, FGETC, MEMMOVE
14
15 * ENTRY: X=null terminated string to edit
16 * A=input path (normally 0)
17 * B=output path (normally 1)
18
19 * EXIT: B=key used to end editing
20 * CC carry set if error (GetStt, Setstt, Write, Read, etc.)
21 * B=error code, if any
22
23 nam Edit/Input Line
24 ttl Assembler Library Module
25
26
27 section .text
28
29 * these variable are all referenced via the
30 * U stack pointer.
31
32 modPD equ 0 first buffer of copy of path descriptor
33 echo equ $04 echo mode
34 bso equ $02 backspace mode
35 bse equ $12 backspace echo char
36 bsp equ $09 backspace char
37 int equ $10 interupt char
38 qut equ $11 quit char
39 bell equ $13 line-overflow char
40
41 maxsize equ 35 temp variable
42 dupPD equ 38 2nd path desc.
43
44 vsize equ dupPD+32 variable stack size
45 strptr equ vsize+2 x on stack
46 inpath equ vsize+0 a on stack
47 outpath equ inpath+1 b on stack
48
49 LINEDIT:
50 pshs a,b,x,y,u
51 leas -vsize,s variable storage area
52 tfr s,u point U to var. area
53 lbsr STRLEN
54 std maxsize,u save max leng.
55 lbeq exit
56
57 * get 2 copies of path descriptor, one to restore with, one to modify
58
59 lda outpath,u
60 leax dupPD,u
61 clrb SS.OPT
62 OS9 I$GetStt
63 bcs err1
64 leax modPD,u
65 clrb
66 OS9 I$GetStt
67 bcs err1
68
69 clrb
70 clr echo,u turn off echo
71 clr int,u ignore keyboard interupt
72 clr qut,u ignore quit
73 clr bso,u backspace overstrike
74 os9 I$SetStt
75 err1
76 lbcs exit
77
78 * parse string and change all controls to space
79
80 fixloop
81 lda ,x+
82 beq fixx
83 lbsr IS_PRINT is it printable?
84 beq fixloop yes, test next
85 lda #$20 change control to space
86 sta -1,x
87 bra fixloop
88 fixx
89
90 * print string at current cursor pos....
91
92 lda outpath,u
93 ldy maxsize,u
94 ldx strptr,u get string start
95 lbsr FPUTS print string
96 bra shiftl1 go to line start
97
98 loop
99 pshs a save outpath
100 lda inpath,u
101 lbsr FGETC get one char
102 tfr a,b keypress to B
103 puls a restore outpath
104 lbcs out
105 cmpb bsp,u backspace?
106 bne delete no, try next
107
108 * backspace one position
109
110 sty -2,s test y
111 beq loop ignore if already at start
112 lbsr bs do a backspace
113 leax -1,x
114 bra loop
115
116 * Delete char at cursor
117
118 delete
119 cmpb #$10 delete char?
120 bne inspace no, try next
121 pshs d,x,y
122 ldd maxsize,u max leng
123 subd 4,s -current pos
124 tfr x,y destination
125 leax 1,x source
126 lbsr MEMMOVE
127 leax d,y end of string
128 lda #$20 put space at end of string
129 sta -1,x
130 tfr y,x
131
132 del1
133 puls d get outpath and char
134 lbsr FPUTS reprint string
135 ldy maxsize,u
136
137 del2
138 cmpy 2,s back up to current cur pos
139 beq del3
140 lbsr bs
141 bra del2
142
143 del3
144 puls x,y clean up and loop
145
146 del4
147 bra loop
148
149
150 inspace
151 cmpb #$11 insert space?
152 bne shiftl no, try next
153 pshs d,x,y
154 ldd maxsize,u
155 subd 4,s
156 subd #1
157 leay 1,x X=source, Y=dest
158 lbsr MEMMOVE
159 ldb #$20 insert space in hole
160 stb ,x
161 bra del1 go reprint and loop
162
163 * move cursor to start of line
164
165 shiftl
166 cmpb #$18 shift left?
167 bne shiftr no, try next
168
169 shiftl1
170 bsr startln backup to start of line
171 ldx strptr,u reset x to start of line
172 bra asciix go loop
173
174 * move cursor to end of line
175
176 shiftr
177 cmpb #$19 shift right?
178 bne right
179
180 shiftr1
181 cmpy maxsize,u
182 bhs del4 back to loop
183 ldb ,x+ move to end by printing string
184 lbsr FPUTC
185 leay 1,y
186 bra shiftr1
187
188 * move 1 pos right
189
190 right
191 cmpb #$09
192 bne maybasci
193 ldb ,x get current char and insert it
194 lbeq loop at end, don't move
195
196 * insert ascii char into buffer
197
198 maybasci
199 tstb insert ascii into buffer
200 lbmi out not ascii
201 cmpb #$20
202 lblo out
203 cmpy maxsize,u room for this?
204 blo ascii yes, insert it
205 ldb bell,u
206 lbsr FPUTC
207 bra asciix to main loop
208
209 ascii
210 stb ,x+
211 lbsr FPUTC
212 leay 1,y
213 asciix
214 lbra loop
215
216 out
217 pshs b save keypress
218 bsr startln
219 ldx strptr,u
220 lbsr FPUTS
221
222
223 leax dupPD,u get original pd
224 lda outpath,u
225 clrb
226 os9 I$SetStt
227 puls a get keypress
228 bcc out1
229 tfr b,a set error to A
230 out1
231 sta outpath,s set B to error/keypress
232
233 * when exiting CARRY will be set if error. B will contain
234 * either the keypress or the error code.
235
236 exit
237 leas vsize,s
238 puls a,b,x,y,u,pc
239
240 * move cursor to start of line
241
242 startln
243 sty -2,s
244 beq startlnx exit if at start
245 startln1
246 bsr bs
247 bne startln1
248
249 startlnx
250 rts
251
252 bs
253 pshs b
254 ldb bse,u
255 lbsr FPUTC
256 leay -1,y
257 puls b,pc
258
259 endsect