Mercurial > hg > Members > kono > nitros9-code
annotate level1/cmds/touch.asm @ 2798:b70d93f8d7ce lwtools-port
Updated coco1/modules/makefile and coco3/modules/makefile to help resolve issues with i(x) and s(x) descriptors.
Updated level1/coco1/modules/makefile & level2/coco3/modules/makefile
so that correct values would be sent to assembler when
building superdesc.asm for s(x).dd and i(x).dd descriptors.
author | drencor-xeen |
---|---|
date | Mon, 28 Jan 2013 16:13:05 -0600 |
parents | 20841f236e32 |
children |
rev | line source |
---|---|
852 | 1 ******************************************************************** |
2 * Touch - Changes last modification date/time | |
3 * | |
4 * $Id$ | |
5 * | |
1325
84ea83668304
Redid comments, reset all rev nibbles that weren't explictly set to 0
boisy
parents:
929
diff
changeset
|
6 * Edt/Rev YYYY/MM/DD Modified by |
84ea83668304
Redid comments, reset all rev nibbles that weren't explictly set to 0
boisy
parents:
929
diff
changeset
|
7 * Comment |
852 | 8 * ------------------------------------------------------------------ |
1325
84ea83668304
Redid comments, reset all rev nibbles that weren't explictly set to 0
boisy
parents:
929
diff
changeset
|
9 * 2 2003/01/11 Boisy G. Pitre |
84ea83668304
Redid comments, reset all rev nibbles that weren't explictly set to 0
boisy
parents:
929
diff
changeset
|
10 * Rewrote touch from scratch, made almost 90% smaller than C version |
84ea83668304
Redid comments, reset all rev nibbles that weren't explictly set to 0
boisy
parents:
929
diff
changeset
|
11 * found in the OS-9 Development System. |
852 | 12 |
13 nam Touch | |
14 ttl Changes last modification date/time | |
15 | |
16 ifp1 | |
17 use defsfile | |
18 endc | |
19 | |
20 * Here are some tweakable options | |
921
617c1b90e623
Added DOHELP conditionals, set all to zero to eliminate help from commands
boisy
parents:
859
diff
changeset
|
21 DOHELP set 0 1 = include help info |
929
c04528763543
stack/parameter size increased to prevent collisions with memory
boisy
parents:
921
diff
changeset
|
22 STACKSZ set 128 estimated stack size |
c04528763543
stack/parameter size increased to prevent collisions with memory
boisy
parents:
921
diff
changeset
|
23 PARMSZ set 256 estimated parameter size |
859 | 24 ZOPTSIZ set 64 max size of -z option's parameter |
852 | 25 |
26 * Module header definitions | |
27 tylg set Prgrm+Objct | |
28 atrv set ReEnt+rev | |
1325
84ea83668304
Redid comments, reset all rev nibbles that weren't explictly set to 0
boisy
parents:
929
diff
changeset
|
29 rev set $00 |
859 | 30 edition set 2 |
852 | 31 |
32 mod eom,name,tylg,atrv,start,size | |
33 | |
34 * Your utility's static storage vars go here | |
35 org 0 | |
36 parmptr rmb 2 pointer to our command line params | |
37 bufptr rmb 2 pointer to user expandable buffer | |
38 bufsiz rmb 2 size of user expandable buffer | |
39 * What follows are utility specific options | |
40 nocreate rmb 1 | |
41 quiterr rmb 1 | |
42 filemode rmb 1 | |
43 filecnt rmb 1 | |
44 zoptflg rmb 1 1 = this option has been processed once already | |
45 zpath rmb 1 path to -z file | |
46 cleartop equ . everything up to here gets cleared at start | |
859 | 47 zopt rmb ZOPTSIZ buffer for what follows after -c= |
852 | 48 * Next is a user adjustable buffer with # modifier on command line. |
49 * Some utilities won't need this, some will. | |
50 * Currently set up to be larger for Level 2 than Level 1 | |
51 * Note: this buffer must come just before the stack | |
52 IFGT Level-1 | |
53 bigbuff rmb 8*1024 8K default buffer for Level 2 | |
54 ELSE | |
55 bigbuff rmb 512 512 byte default buffer for Level 1 | |
56 ENDC | |
57 * Finally the stack for any PSHS/PULS/BSR/LBSRs that we might do | |
929
c04528763543
stack/parameter size increased to prevent collisions with memory
boisy
parents:
921
diff
changeset
|
58 rmb STACKSZ+PARMSZ |
852 | 59 size equ . |
60 | |
61 * The utility name and edition goes here | |
62 name fcs /Touch/ | |
63 fcb edition | |
64 | |
65 * Place constant strings here | |
66 IFNE DOHELP | |
67 HlpMsg fcb C$LF | |
68 fcc /Use: Touch [<opts>] <path> [<path>] [<opts>]/ | |
69 fcb C$LF | |
70 fcc / -c = don't create files/ | |
71 fcb C$LF | |
72 fcc / -q = don't quit on error/ | |
73 fcb C$LF | |
74 fcc / -x = search execution directory/ | |
75 fcb C$LF | |
859 | 76 fcc / -z = get files from standard input/ |
852 | 77 fcb C$LF |
859 | 78 fcc / -z=<file> get files from <file>/ |
852 | 79 fcb C$LF |
80 CR fcb C$CR | |
81 HlpMsgL equ *-HlpMsg | |
82 ENDC | |
83 UnkOpt fcc /unknown option: / | |
84 UnkOptL equ *-UnkOpt | |
85 CantTch fcc /can't touch "/ | |
86 CantTchL equ *-CantTch | |
859 | 87 EndCant fcc /" - / |
88 EndCantL equ *-EndCant | |
852 | 89 |
90 * Here's how registers are set when this process is forked: | |
91 * | |
92 * +-----------------+ <-- Y (highest address) | |
93 * ! Parameter ! | |
94 * ! Area ! | |
95 * +-----------------+ <-- X, SP | |
96 * ! Data Area ! | |
97 * +-----------------+ | |
98 * ! Direct Page ! | |
99 * +-----------------+ <-- U, DP (lowest address) | |
100 * | |
101 * D = parameter area size | |
102 * PC = module entry point abs. address | |
103 * CC = F=0, I=0, others undefined | |
104 | |
105 * The start of the program is here. | |
106 * Before any command line processing is done, we clear out | |
107 * our static memory from U to cleartop, then determine the | |
108 * size of our data area (minus the stack). | |
109 start pshs u,x save registers for later | |
110 leax <cleartop,u point to end of area to zero out | |
111 IFNE H6309 | |
112 subr u,x subtract U from X | |
113 tfr x,w and put X in W | |
114 clr ,-s put a zero on the stack | |
115 tfm s,u+ and use TFM to clear starting at U | |
116 leas 1,s clean up the stack | |
117 ELSE | |
118 pshs x save end pointer on stack | |
119 clrnxt clr ,u+ clear out | |
120 cmpu ,s done? | |
121 bne clrnxt branch if not | |
122 leas 2,s else clear stack | |
123 ENDC | |
124 puls x,u and restore our earlier saved registers | |
125 leay bigbuff,u point Y to copy buffer offset in U | |
126 stx <parmptr save parameter pointer | |
127 sty <bufptr save pointer to buffer | |
128 tfr s,d place top of stack in D | |
129 IFNE H6309 | |
130 subr y,d | |
131 ELSE | |
132 pshs y save Y on stack | |
133 subd ,s++ get size of space between copybuf and X | |
134 ENDC | |
929
c04528763543
stack/parameter size increased to prevent collisions with memory
boisy
parents:
921
diff
changeset
|
135 subd #STACKSZ+PARMSZ subtract out our stack |
852 | 136 std <bufsiz size of our buffer |
137 | |
138 * At this point we have determined our buffer space and saved pointers | |
139 * for later use. Now we will parse the command line for options that | |
140 * begin with - | |
859 | 141 lda ,x |
852 | 142 cmpa #C$CR CR? |
143 lbeq ShowHelp if so, no parameters... show help and exit | |
144 GetChar lda ,x+ get next character on cmd line | |
145 cmpa #C$CR CR? | |
146 lbeq DoTouch if so, do whatever this utility does | |
147 cmpa #'- is it an option? | |
148 beq GetDash if so, process it | |
149 inc <filecnt else must be a non-option argument (file) | |
150 lbsr SkipNSpc move past the argument | |
151 ChkDash lbsr SkipSpcs and any following spaces | |
152 bra GetChar start processing again | |
153 GetDash lda #C$SPAC get a space char | |
154 sta -1,x and wipe out the dash from the cmd line | |
155 GetDash2 ldd ,x+ load option char and char following | |
156 ora #$20 make lowercase | |
157 IsItC cmpa #'c is it this option? | |
158 bne IsItQ branch if not | |
159 sta <nocreate | |
160 lbra FixCmdLn | |
161 IsItQ cmpa #'q is it this option? | |
162 bne IsItX branch if not | |
163 inc <quiterr | |
164 lbra FixCmdLn | |
165 IsItX cmpa #'x is it this option? | |
166 bne IsItZ branch if not | |
167 lda #EXEC. | |
168 sta <filemode | |
169 bra FixCmdLn | |
170 IsItZ cmpa #'z is it this option? | |
171 bne BadOpt branch if not | |
172 tst <zoptflg was this option already specified? | |
173 bne BadOpt show help if so | |
174 sta <zoptflg else tag this option as parsed | |
175 cmpb #'= 2nd char =? | |
176 bne FixCmdLn | |
177 GetZFile ldb #C$SPAC get space | |
178 stb -$01,x write over c | |
179 stb ,x+ and = sign, inc X to dest dir | |
180 * check for valid char after -z= | |
181 lda ,x | |
182 cmpa #C$SPAC | |
183 lbeq ShowHelp | |
184 cmpa #C$COMA | |
185 lbeq ShowHelp | |
186 cmpa #C$CR | |
187 lbeq ShowHelp | |
188 leay <zopt,u point Y to parameber buffer | |
189 tfr y,d transfer Y to D | |
859 | 190 addd #ZOPTSIZ |
852 | 191 pshs b,a save updated ptr value |
192 ldb #C$SPAC get space | |
193 L0339 lda ,x get byte at X | |
194 stb ,x+ store space at X and inc | |
195 sta ,y+ save loaded byte at Y and inc | |
196 cmpy ,s are we at end? | |
197 beq L035D branch if so (buffer too small) | |
198 cmpa #C$SPAC else is char in A a space? | |
199 beq L0350 branch if so | |
200 cmpa #C$COMA coma? | |
201 beq L0350 branch if so | |
202 cmpa #C$CR cr? | |
203 bne L0339 get next byte if not | |
204 L0350 leax -1,x | |
205 sta ,x restore previous A | |
206 leas $02,s kill stack | |
207 * attempt to open a path to the file | |
208 pshs x | |
209 leax <zopt,u | |
210 lda #READ. | |
211 os9 I$Open | |
212 lbcs Exit | |
213 sta <zpath | |
214 puls x | |
215 lbra ChkDash | |
216 L035D leas $02,s | |
217 ldb #$BF else buffer size too small | |
218 orcc #Carry | |
219 lbra Exit | |
220 FixCmdLn lda #C$SPAC get space | |
221 sta -$01,x and wipe out option character | |
222 cmpb #'0 | |
223 lblt ChkDash start dash option processing again | |
224 lbra GetDash possibly another option following? | |
225 | |
226 * We branch here if we encounter an unknown option character | |
227 * A = bad option character | |
228 BadOpt leax UnkOpt,pcr | |
229 ldy #UnkOptL | |
230 ldb #C$CR | |
231 pshs d save bad option and CR on stack | |
232 lda #$02 stderr | |
233 os9 I$Write | |
234 leax ,s point X at option char on stack | |
235 os9 I$WritLn print option and CR | |
236 puls d clean up stack | |
237 lbra ShowHelp | |
238 | |
239 | |
240 * At this point options are processed. | |
241 * We load X with our parameter pointer and go down the command line | |
242 * looking at each file to process (options have been wiped out with | |
243 * spaces) | |
244 * | |
245 * Note, the following two instructions may not be needed, depending on | |
246 * if your utility requires a non-option on the command line. | |
859 | 247 DoTouch tst <zoptflg -z specified? |
248 beq DoFiles no, do any files on command line | |
249 ReadZ lda <zpath | |
250 ldy #80 | |
251 os9 I$ReadLn | |
252 lbsr SkipSpcs | |
253 cmpa #C$CR | |
254 beq ClosEx | |
255 bcs TestErr | |
256 bsr ProcFile | |
257 bra ReadZ | |
258 TestErr cmpb #E$EOF | |
259 lbne Exit | |
260 tsta | |
261 lbeq ExitOk | |
262 ClosEx os9 I$Close close path to -z= file | |
263 lbra ExitOk | |
264 | |
265 DoFiles tst <filecnt we should have at least one file on cmdline | |
852 | 266 lbeq ShowHelp if not, exit with error |
267 ldx <parmptr get our parameter pointer off stack | |
268 DoLoop lbsr SkipSpcs skip any leading spaces | |
269 cmpa #C$CR end of parameters? | |
270 beq ExitOk if so, end the utility | |
271 pshs x save pointer to arg | |
272 bsr ProcFile process file at X | |
273 puls x get arg pointer | |
274 lbsr SkipNSpc skip the argument we just processed | |
275 bra DoLoop | |
276 | |
277 * This routine processes one file at a time. | |
278 * Entry: X = ptr to argument on the command line. | |
279 * On exit, X can point to the argument or past it. | |
280 * Note that there are NO leading spaces. | |
281 * They have been skipped by the caller. | |
282 * The following code just echos the command line argument, followed | |
283 * by a carriage return. | |
284 ProcFile | |
859 | 285 lda #WRITE. |
286 ora <filemode | |
287 pshs x | |
288 os9 I$Open | |
289 puls x | |
290 bcc CloseIt | |
291 ora #DIR. | |
852 | 292 pshs x |
293 os9 I$Open | |
294 puls x | |
295 bcc CloseIt | |
296 * open failed... should we do create? | |
297 tst <nocreate | |
298 beq DoCreate | |
299 ChkQuit bsr CantTouch | |
300 tst <quiterr | |
859 | 301 beq ExitOK |
852 | 302 bra ProcRTS |
303 DoCreate ldb #PREAD.+UPDAT. | |
859 | 304 pshs x |
852 | 305 os9 I$Create |
859 | 306 puls x |
852 | 307 bcs ChkQuit |
308 CloseIt os9 I$Close | |
309 ProcRTS rts | |
310 | |
311 CantTouch | |
859 | 312 pshs x,b save pointer to file and error code |
852 | 313 leax CantTch,pcr |
314 lda #$02 | |
315 ldy #CantTchL | |
316 os9 I$Write | |
859 | 317 ldx 1,s |
318 pshs x | |
852 | 319 bsr StrLen |
320 puls x | |
321 os9 I$Write | |
322 leax EndCant,pcr | |
859 | 323 ldy #EndCantL |
324 os9 I$Write | |
325 puls b | |
326 os9 F$PErr | |
852 | 327 puls x,pc |
328 | |
329 ShowHelp equ * | |
330 IFNE DOHELP | |
331 leax >HlpMsg,pcr point to help message | |
332 ldy #HlpMsgL get length | |
333 lda #$02 std error | |
334 os9 I$WritLn write it | |
335 ENDC | |
336 ExitOk clrb clear carry | |
337 Exit os9 F$Exit and exit | |
338 | |
339 * This routine counts the number of non-whitespace characters | |
340 * starting at X | |
341 * | |
342 * Entry: | |
343 * X = ptr to string (space, comma or CR terminated) | |
344 * Exit: | |
345 * Y = length of string | |
346 * X = ptr to byte after string | |
347 StrLen pshs a | |
348 ldy #$0000 | |
349 StrLenLp lda ,x+ | |
350 cmpa #C$SPAC | |
351 beq StrLenEx | |
352 cmpa #C$COMA | |
353 beq StrLenEx | |
354 cmpa #C$CR | |
355 beq StrLenEx | |
356 leay 1,y | |
357 bra StrLenLp | |
358 StrLenEx puls a,pc | |
359 | |
360 * This routine copies a string of text from X to Y until | |
361 * a whitespace character or CR is encountered | |
362 * | |
363 * Entry: | |
364 * X = ptr to src string | |
365 * Y = ptr to dest string | |
366 * Exit: | |
367 * D = number of bytes copied | |
368 * X = ptr to byte after original string | |
369 * Y = ptr to byte after copied string | |
370 StrCpy pshs u | |
371 ldu #$0000 | |
372 CopyFnLp lda ,x+ | |
373 cmpa #C$SPAC | |
374 beq CopyFnEx | |
375 cmpa #C$COMA | |
376 beq CopyFnEx | |
377 cmpa #C$CR | |
378 beq CopyFnEx | |
379 sta ,y+ | |
380 leau 1,u | |
381 bra CopyFnLp | |
382 CopyFnEx tfr u,d | |
383 puls u,pc | |
384 | |
385 * This routine skip over spaces and commas | |
386 * | |
387 * Entry: | |
388 * X = ptr to data to parse | |
389 * Exit: | |
390 * X = ptr to first non-whitespace char | |
391 * A = non-whitespace char | |
392 SkipSpcs lda ,x+ | |
393 cmpa #C$SPAC | |
394 beq SkipSpcs | |
395 cmpa #C$COMA | |
396 beq SkipSpcs | |
397 leax -1,x | |
398 rts | |
399 | |
400 * This routine skips over everything but spaces, commas and CRs | |
401 * | |
402 * Entry: | |
403 * X = ptr to data to parse | |
404 * Exit: | |
405 * X = ptr to first whitespace char | |
406 * A = whitespace char | |
407 SkipNSpc lda ,x+ | |
408 cmpa #C$SPAC | |
409 beq EatOut | |
410 cmpa #C$COMA | |
411 beq EatOut | |
412 cmpa #C$CR | |
413 bne SkipNSpc | |
414 EatOut leax -1,x | |
415 rts | |
416 | |
417 emod | |
418 eom equ * | |
419 end |