Mercurial > hg > Members > kono > nitros9-code
comparison level1/cmds/copy.asm @ 802:3a308921e135 basic09v010100 nos9l2v020100beta2 os9l2v030002beta2
New version of copy with OSK like features
author | boisy |
---|---|
date | Sun, 12 Jan 2003 23:08:10 +0000 |
parents | 1810b051d07e |
children | 92e1ff829e97 |
comparison
equal
deleted
inserted
replaced
801:e3a18315da10 | 802:3a308921e135 |
---|---|
3 * | 3 * |
4 * $Id$ | 4 * $Id$ |
5 * | 5 * |
6 * Ed. Comments Who YY/MM/DD | 6 * Ed. Comments Who YY/MM/DD |
7 * ------------------------------------------------------------------ | 7 * ------------------------------------------------------------------ |
8 * 10 Reworked RML | 8 * 9 From Tandy OS-9 Level One VR 02.00.00 |
9 * 10 Reworked RML | |
10 * 11 Added useful options, made more robust BGP 03/01/11 | |
9 | 11 |
10 nam Copy | 12 nam Copy |
11 ttl File copy utility | 13 ttl File copy utility |
12 | 14 |
13 * Edition 10 rewrite 10/28/88 - RML | 15 ifp1 |
14 | |
15 ifp1 | |
16 use defsfile | 16 use defsfile |
17 use rbfdefs | 17 use rbfdefs |
18 endc | 18 endc |
19 | 19 |
20 tylg set Prgrm+Objct | 20 * Tweakable options |
21 DOHELP set 1 | |
22 | |
23 tylg set Prgrm+Objct | |
21 atrv set ReEnt+rev | 24 atrv set ReEnt+rev |
22 rev set $01 | 25 rev set $01 |
23 edition set 10 | 26 edition set 11 |
24 | 27 |
25 mod eom,name,tylg,atrv,start,size | 28 mod eom,name,tylg,atrv,start,size |
26 | 29 |
27 inpath rmb 1 input path number | 30 STCKSIZE equ 64 our stack size |
28 outpath rmb 1 output path number | 31 DDIRBSIZ equ 64 destination directory buffer size |
29 indevtyp rmb 1 input device type (1 = RBF) | 32 |
30 verify rmb 1 verify on/off (1=on) | 33 org 0 |
31 bufsize rmb 2 read/write buffer size | 34 rdbufptr rmb 2 |
32 fsizemsb rmb 2 msb's of file size | 35 parmptr rmb 2 |
33 fsizelsb rmb 2 lsb's of file size | 36 srcpath rmb 1 |
34 writemsb rmb 2 msb's of bytes written to output | 37 dstpath rmb 1 |
35 writelsb rmb 2 lsb's of bytes written to output | 38 devtyp rmb 1 |
36 single rmb 1 single drive copy flag (1=yes) | 39 bufsiz rmb 2 |
37 attribs rmb 1 file attributes | 40 srcflsiz rmb 4 |
38 fdbuff rmb 16 File Descriptor buffer | 41 abortflg rmb 1 |
39 optbuff rmb 32 Path Descriptor Options Buffer | 42 quiet rmb 1 |
40 stack rmb 448 stack storage | 43 single rmb 1 |
41 vfybuff rmb 256 verify buffer | 44 rewrite rmb 1 |
42 buffer rmb $2000-. read/write buffer (minimum..will expand with mem mod) | 45 filecnt rmb 1 |
46 srccnt rmb 1 | |
47 srcmode rmb 1 | |
48 wopt rmb 1 | |
49 srcfname rmb 2 | |
50 dstfptr rmb 2 | |
51 wfileptr rmb 2 | |
52 wfilelen rmb 2 | |
53 lstfopen rmb 2 pointer to name of last file attempted open | |
54 lstfopln rmb 2 length of last file atteppted open | |
55 srcattr rmb 1 | |
56 fdbufcpy rmb 16 | |
57 optbuf rmb 32 | |
58 wdest rmb DDIRBSIZ portion after '-w=' | |
59 rmb DDIRBSIZ additional space | |
60 * Note: copy buffer must come just before the stack | |
61 IFGT Level-1 | |
62 copybuff rmb 8*1024 8K default buffer for Level 2 | |
63 ELSE | |
64 copybuff rmb 512 512 byte default buffer for Level 1 | |
65 ENDC | |
66 stack rmb STCKSIZE | |
43 size equ . | 67 size equ . |
44 | 68 |
45 name fcs /Copy/ | 69 name fcs /Copy/ |
46 fcb edition | 70 fcb edition |
47 | 71 |
48 start leas vfybuff,u set stack pointer to 512 | 72 SrcPmpt fcc /Ready SOURCE, hit C to continue: / |
49 pshs u save u reg | 73 SrcPmptL equ *-SrcPmpt |
50 leau <optbuff,u point u to 20th byte | 74 DstPmpt fcc /Ready DESTINATION, hit C to continue: / |
51 | 75 DstPmptL equ *-DstPmpt |
52 clearit clr ,-u clear byte | 76 CrRtn fcb C$CR |
53 cmpu ,s done ? | 77 IFNE DOHELP |
54 bhi clearit loop back | 78 HlpMsg fcb C$LF |
55 tfr y,d move in top of mem (after param area) | 79 fcc /Use: Copy [<opts>] <srcpath> [<dstpath>] [<opts>]/ |
56 subd ,s++ subtract current stack | 80 fcb C$LF |
57 subd #$0300 and back off variable storage | 81 fcc / -a abort on error/ |
58 clrb round off to page bondary | 82 fcb C$LF |
59 std <bufsize buffer size | 83 fcc / -p don't print file nammes copied (with -w option only)/ |
60 pshs x save x register | 84 fcb C$LF |
61 | 85 fcc / -r rewrite destination/ |
62 getopt lda ,x+ get a char | 86 fcb C$LF |
63 cmpa #'- was it a '-'?? | 87 fcc / -s single drive copy/ |
64 beq chkopt yes..go check opt | 88 fcb C$LF |
65 cmpa #C$CR was it a <cr>?? | 89 fcc / -w=<dir> copy files to <dir>/ |
66 bne getopt no..check next char | 90 fcb C$LF |
67 bra openin else done..go finish processing | 91 fcc / -x look in execution directory for source/ |
68 | 92 fcb C$CR |
69 chkopt ldd ,x+ get next 2 chars | 93 HlpMsgL equ *-HlpMsg |
70 eora #'S check if its an S | 94 ENDC |
71 anda #$DF make upper case | 95 PLIncmp fcc /copy: destination must be complete pathlist/ |
72 lbne sndinstr not an s.. send instructions | 96 fcb C$CR |
73 cmpb #$30 else check if next char is number or letter | 97 TooMany fcc /copy: must specify output directory if more than 2 files/ |
74 lbhs sndinstr yup...send instructions | 98 fcb C$CR |
75 inc <single set s option | 99 Copying fcc /copying / |
76 bra getopt and check next char | 100 CopyingL equ *-Copying |
77 | 101 CopyTo fcc / to / |
78 openin puls x restore line pointer | 102 CopyToL equ *-CopyTo |
79 lda #READ. open first file | 103 Cont fcc !Continue (y/n) ?! |
80 os9 I$Open | 104 ContL equ *-Cont |
81 lbcs chkerr error..go see what it was | 105 CantCpy fcc /copy: can't open / |
82 sta <inpath save path number | 106 CantCpyL equ *-CantCpy |
83 pshs x save second path name start | 107 SpcDsh fcc / - / |
84 leax <fdbuff,u point to FD buffer | 108 SpcDshL equ *-SpcDsh |
85 ldy #FD.SEG bytes to read | 109 |
86 ldb #SS.FD get file descriptor | 110 * +-----------------+ <-- Y (highest address) |
87 os9 I$GetStt | 111 * ! ! |
88 puls x restore line pointer | 112 * ! Parameter ! |
89 bcs getintyp skip this on eror | 113 * ! Area ! |
90 tst <single single drive copy ? | 114 * ! ! |
91 beq getintyp no..skip this stuff | 115 * +-----------------+ <-- X, SP |
92 lda ,x get first char of path name | 116 * ! ! |
93 ldb #E$BPNam load bad path name error message | 117 * ! ! |
94 cmpa #PDELIM was it a path separaor ? | 118 * ! Data Area ! |
95 bne errjump nope..error | 119 * ! ! |
96 | 120 * ! ! |
97 getintyp pshs x save out path name start | 121 * +-----------------+ |
98 lda <inpath get path number | 122 * ! Direct Page ! |
99 bsr getopts get option section | 123 * +-----------------+ <-- U, DP (lowest address) |
100 lda ,x get device type | 124 * |
101 sta <indevtyp save it | 125 * D = parameter area size |
102 ldb #PREAD.+EXEC.+READ.+WRITE. default attributes...read,write,execute,public | 126 * PC = module entry point abs. address |
103 cmpa #DT.RBF was device type RBF ? | 127 * CC = F=0, I=0, others undefined |
104 bne openout nope...don't get file size/attributes | 128 |
105 pshs u,x save registers | 129 start pshs u,x |
106 lda <inpath get path number | 130 leax <wdest,u |
107 ldb #SS.Size Get File size | 131 pshs x |
108 bsr getstat do the GetStt call..exit on error | 132 clrnxt clr ,u+ |
109 stx <fsizemsb save 2 msb's of file size | 133 cmpu ,s |
110 stu <fsizelsb save 2 lsb's of file size | 134 bne clrnxt |
111 puls u,x restore registers | 135 leas 2,s |
112 ldb <PD.ATT-PD.OPT,x get file attributes | 136 puls x,u |
113 | 137 leay copybuff,u point Y to copy buffer offset in U |
114 openout stb <attribs save attributes | 138 stx <parmptr save parameter pointer |
115 ldx ,s get start of second path name | 139 sty <rdbufptr save pointer to buffer |
116 lbsr destsnd send destination msg | 140 tfr s,d place top of stack in D |
117 lda #UPDAT. open file for update | 141 pshs y save Y on stack |
118 ldb <attribs get attributes | 142 subd ,s++ get size of space between copybuf and X |
119 os9 I$Create create the file | 143 subd #STCKSIZE subtract out our stack |
120 puls x restore x register | 144 std <bufsiz size of our buffer |
121 bcc open010 no error..skip this | 145 lbsr SkipSpcs move past any spaces on command line |
122 inc <verify set verify off | 146 cmpa #C$CR CR? |
123 lda #WRITE. open filein write only mode | 147 lbeq ShowHelp if so, show help |
124 ldb <attribs get atributes | 148 GetNChr lda ,x+ |
125 os9 I$Create create the file | 149 cmpa #C$CR CR? |
126 bcs errjump exit on error | 150 lbeq CpyFiles branch if so |
127 | 151 cmpa #'- option? |
128 open010 sta <outpath save second path number | 152 beq GetDash |
129 bsr getopts get option section | 153 inc <filecnt must be a file |
130 ldb ,x get device type | 154 lbsr SkipNSpc else go past non-spaces |
131 cmpb #DT.RBF was it RBF | 155 ChkDash lbsr SkipSpcs and any following spaces |
132 beq setvfy yup...skip this | 156 bra GetNChr and check for Cr |
133 inc <verify set verify off | 157 GetDash lda #C$SPAC |
134 bra mainloop and skip all this | 158 sta -1,x |
135 | 159 GetDash2 ldd ,x+ load option char and char following |
136 errjump lbra errexit nope....error | 160 anda #$5F |
137 | 161 cmpa #'S single drive copy? |
138 getopts leax <optbuff,u point to buffer | 162 bne IsItA branch if not |
139 ldb #SS.Opt get option section of path descritor | 163 inc <single |
140 | 164 lbra FixCmdLn |
141 getstat os9 I$GetStt | 165 IsItA cmpa #'A abort option? |
142 bcs errjump exit on error | 166 bne IsItP branch if not |
167 inc <abortflg | |
168 bra FixCmdLn | |
169 IsItP cmpa #'P supress output? | |
170 bne IsItX branch if not | |
171 inc <quiet | |
172 bra FixCmdLn | |
173 IsItX cmpa #'X execution dir? | |
174 bne IsItW branch if not | |
175 lda #EXEC. else get EXEC. | |
176 sta <srcmode and save as source mode | |
177 bra FixCmdLn | |
178 IsItW cmpa #'W directory specification? | |
179 bne IsItR branch if not | |
180 tst <wopt already specified? | |
181 bne BadOpt show help if so | |
182 cmpb #'= 2nd char =? | |
183 bne BadOpt show help if not | |
184 inc <wopt else tag wopt as specified | |
185 ldb #C$SPAC get space | |
186 stb -$01,x write over w | |
187 stb ,x+ and = sign, inc X to dest dir | |
188 * check for valid char after -w= | |
189 lda ,x | |
190 cmpa #C$SPAC | |
191 lbeq ShowHelp | |
192 cmpa #C$COMA | |
193 lbeq ShowHelp | |
194 cmpa #C$CR | |
195 lbeq ShowHelp | |
196 leay <wdest,u point Y to parameber buffer | |
197 sty <dstfptr save pointer to destination file | |
198 tfr y,d transfer Y to D | |
199 addd #DDIRBSIZ add size | |
200 pshs b,a save updated ptr value | |
201 ldb #C$SPAC get space | |
202 L0339 lda ,x get byte at X | |
203 stb ,x+ store space at X and inc | |
204 sta ,y+ save loaded byte at Y and inc | |
205 cmpy ,s are we at end? | |
206 beq L035D branch if so (buffer too small) | |
207 cmpa #C$SPAC else is char in A a space? | |
208 beq L0350 branch if so | |
209 cmpa #C$COMA coma? | |
210 beq L0350 branch if so | |
211 cmpa #C$CR cr? | |
212 bne L0339 get next byte if not | |
213 L0350 leax -1,x | |
214 sta ,x restore previous A | |
215 lda #PDELIM get pathlist delimiter | |
216 sta -$01,y save slash at end (for building path later) | |
217 sty <wfileptr save pointer for -w pathlist file copying | |
218 leas $02,s kill stack | |
219 lbra ChkDash | |
220 L035D leas $02,s | |
221 ldb #$BF else buffer size too small | |
222 orcc #Carry | |
223 lbra Exit | |
224 IsItR cmpa #'R rewrite? | |
225 bne BadOpt branch if not | |
226 inc <rewrite | |
227 FixCmdLn lda #C$SPAC get space | |
228 sta -$01,x and wipe out option character | |
229 cmpb #'0 | |
230 lblt ChkDash start dash option processing again | |
231 lbra GetDash possibly another option following? | |
232 | |
233 BadOpt puls x | |
234 lbra ShowHelp | |
235 | |
236 CopyToW ldx <srcfname get ptr to next file to process | |
237 * In case the source file name has a / in it (i.e. /dd/x/y/fname), | |
238 * we go past the file and then back up to either the first / we | |
239 * encounter, or a space (be sure we don't go past parmptr) | |
240 lda ,x | |
241 cmpa #C$CR carriage return? | |
242 lbeq ExitOk yep, no more files | |
243 lbsr SkipNSpc skip over filename | |
244 * X points to first char after file name (space, comma or CR) | |
245 L038B cmpx <parmptr are we at start of command line? | |
246 beq PlugIt2 if so, we can't go further back | |
247 lda ,-x get byte | |
248 cmpa #PDELIM path delimiter? | |
249 beq PlugIt branch if so | |
250 cmpa #C$SPAC space? | |
251 beq PlugIt branch if so | |
252 cmpa #C$COMA comma? | |
253 beq PlugIt branch if so | |
254 bra L038B else get next char | |
255 PlugIt leax 1,x go forward 1 | |
256 PlugIt2 ldy <wfileptr get address past xxxx/ (specified by -w=) | |
257 lbsr StrCpy copy filenamme | |
258 std <wfilelen save file length | |
259 lda #C$CR get CR | |
260 sta ,y and terminate | |
261 * ldx <wopt | |
262 * stx <wfileptr | |
143 rts | 263 rts |
144 | 264 |
145 setvfy tst <verify do we want verify on | 265 * At this point options are processed, so we need to start copying files |
146 bne setsiz nope...dont set driver verify on | 266 CpyFiles tst <filecnt we should have at least one file on cmdline |
147 ldb #1 verify | 267 lbeq ShowHelp if not, exit with error |
148 stb PD.VFY-PD.OPT,x turn verify on | 268 ldx <parmptr get our parameter pointer off stack |
149 ldb #SS.OPT set options | 269 lbsr SkipSpcs skip any leading spaces |
150 os9 I$SetStt | 270 tst <wopt -w specified? |
151 bcs errjump exit on error | 271 beq L03C5 branch if not |
152 | 272 stx <srcfname else save start of parameter pointer as next file |
153 setsiz lda <indevtyp get device type | 273 clr <single no single option with -w |
154 cmpa #DT.RBF is it an RBF file | 274 L03BE bsr CopyToW copy file at <srcfname to -w buffer |
155 bne mainloop nope...dont preset file size | 275 bra OpenSrc |
156 pshs u save register | 276 * This code handles single file copy (i.e. copy file1 file2) |
157 lda <outpath get out path number | 277 * or a single disk copy (i.e. copy -s abc) |
158 ldb #SS.Size set file size | 278 L03C5 lbsr GetSDFl else get source/destination files |
159 ldx <fsizemsb get 2 msb's of in file size | 279 bcc L03D4 branch if we got both ok |
160 ldu <fsizelsb get 2 lsb's of in file size | 280 tst <single is this a single drive copy? |
161 os9 I$SetStt set the size | 281 lbne PListErr if not, user didn't specify enough files |
162 bcs errjump exit on error | 282 lbcs Exit if error, exit |
163 puls u restore register | 283 * test for right number of files |
164 lda <outpath get out path number | 284 L03D4 lda <filecnt get total file count |
165 leax <fdbuff,u point to FD buffer | 285 cmpa #2 should be no more than two files |
166 ldy #FD.SEG number of bytes to write | 286 ble OpenSrc |
167 ldb #SS.FD write out the FD (for dates,etc.) | 287 leax TooMany,pcr |
168 os9 I$SetStt | 288 lbsr WrLine |
169 | 289 lbra ExitOk |
170 mainloop leax buffer,u point to buffer | 290 OpenSrc ldx <srcfname get file to open |
171 clra source drive code | 291 pshs x |
172 lbsr chkdrive send source switch msg | 292 lbsr StrLen get length |
173 lda <inpath get in path number | 293 std <lstfopln save length |
174 ldy <bufsize get buffer size | 294 puls x |
175 os9 I$Read read a block | 295 lda #READ. read mode |
176 bcs chkeof2 if error..go check which one | 296 ora <srcmode or in any additional modes (i.e. EXEC.) |
177 lbsr destsnd send destination switch msg | 297 stx <lstfopen save pointer to last file open var |
178 lda <outpath get out path number | 298 os9 I$Open open source file |
179 os9 I$Write write the block out | 299 bcc L03FA branch if open ok |
180 bcs errjump exit on error | 300 cmpx <srcfname did open go past pathlist? |
181 tst <verify are we verifying ? | 301 bne OpenFail branch if so |
182 bne chkeof skip this | 302 lbsr SkipNSpc else skip over failed filename |
183 pshs u,y save registers | 303 lbsr SkipSpcs and any trailing spaces |
184 ldx <writemsb get 2 msb's of last write | 304 OpenFail stx <srcfname save updated pathlist pointer (points to next file on cmd line) |
185 ldu <writelsb get 2 lsb's of last write | 305 lbra ShutDown |
186 lda <outpath get out path number | 306 L03FA sta <srcpath save source path |
187 os9 I$Seek | 307 pshs a save path |
188 bcs errjump exit on error | 308 lbsr SkipSpcs destroy any leading spaces |
189 ldu 2,s get original u back | 309 stx <srcfname and save pointer to next source filename |
190 leau buffer,u point to buffer start | 310 lbsr StrLen get length |
191 ldd ,s get bytes written | 311 std <lstfopln save length |
192 addd <writelsb add on to current 2 lsb positions | 312 puls a get path off stack |
193 std <writelsb save them | 313 leax <fdbufcpy,u point to FD buffer |
194 ldd ,s get bytes written | 314 ldy #FD.SEG number of bytes |
195 bcc vfy000 skip if no carry | 315 ldb #SS.FD |
196 leax 1,x bump up 2 msb's | 316 os9 I$GetStt get file's file descriptor |
197 stx <writemsb and save them | 317 bcs L041B branch if error |
198 | 318 tst <single single drive copy? |
199 vfy000 ldy #$0100 chars to read for verify | 319 beq L041B branch if not |
200 std ,s save it | 320 lda [<dstfptr,u] get first char of destination filename |
201 tsta did we write more than 255 bytes ? | 321 ldb #E$BPNam prepare for possible error |
202 bne vfy010 yes...only read 256 | 322 cmpa #PDELIM path has leading slash? |
203 tfr d,y else xfer amount we did write | 323 lbne PListErr if not, show error |
204 | 324 L041B lda <srcpath get source path |
205 vfy010 ldx 2,s get u register | 325 leax <optbuf,u point to options buffer |
206 leax $200,x point to start of verify buffer | 326 clrb was: ldb #SS.Opt |
207 lda <outpath get output path number | 327 os9 I$GetStt get path options |
208 os9 I$Read read a block in | 328 lbcs ShutDown branch if error |
209 bcs errexit exit on error | 329 lda ,x get device type |
210 | 330 sta <devtyp save |
211 vfy020 lda ,u+ get char from in buffer | 331 ldb #$0F |
212 cmpa ,x+ get char from out buffer | 332 cmpa #DT.RBF rbf device? |
213 bne snderr1 not equal...send write verfiy msg | 333 bne L0449 branch if not |
214 leay -1,y decrement read count | 334 pshs u,x save regs |
215 bne vfy020 if more..loop back | 335 lda <srcpath get source path |
216 ldd ,s get write count back | 336 ldb #SS.Size |
217 subd #$0100 subtract verify buffer size | 337 os9 I$GetStt get size |
218 bhi vfy000 if more left...loop back | 338 lbcs ShutDown |
219 puls u,y else restore registers | 339 stx <srcflsiz save file size |
220 | 340 stu <srcflsiz+2 |
221 chkeof lda <inpath get in path number | 341 puls u,x restore regs |
222 ldb #SS.EOF check for end of file | 342 ldb <PD.ATT-PD.OPT,x get source file's attributes |
223 os9 I$GetStt | 343 L0449 stb <srcattr save |
224 bcc mainloop nope...loop back | 344 lda #$01 |
225 cmpb #E$EOF are we at end of file ? | 345 lbsr SwapDsk check for single disk copy and prompt if necessary |
226 beq closeout yes...close file | 346 L0450 ldx <dstfptr point to destination file |
227 | 347 pshs x |
228 | 348 lbsr StrLen get length |
229 chkeof2 cmpb #E$EOF check for end of file | 349 std <lstfopln save length |
230 bne errexit nope...error exit | 350 puls x |
231 bsr destsnd send msg for disk switch | 351 lda #WRITE. write mode |
232 | 352 ldb <srcattr get source attributes |
233 closeout lda <outpath get out path number | 353 stx <lstfopen |
234 os9 I$Close close the file | 354 os9 I$Create create file |
235 bcc exitok exit w/o error if o.k. | 355 bcc L048B branch if create ok |
236 bra errexit else error exit | 356 tst <rewrite rewrite flag set? |
237 | 357 lbeq ShutDown branch if no |
238 errmsg1 fcb C$BELL | 358 cmpb #E$CEF file already exists? |
239 fcc /Error - write verification failed./ | 359 lbne ShutDown branch if any other error |
240 fcb C$CR | 360 L047A os9 I$Delete delete file first |
241 | 361 lbcs ShutDown branch if error |
242 snderr1 leax errmsg1,pcr address of 'write verify failed' msg | 362 bra L0450 else try opening again |
243 bsr sndline send it | 363 L048B sta <dstpath save destination path |
244 comb set carry | 364 tst <wopt w option specified? |
245 ldb #$01 set error | 365 beq GetOpts branch iff not |
246 bra errexit exit | 366 tst <quiet p option specified? |
247 | 367 bne GetOpts branch if so |
248 chkerr cmpb #E$BPNam was it bad path name | 368 pshs a else save dest path on stack |
249 bne errexit error exit | 369 leax >Copying,pcr else print 'Copying...' |
250 | 370 ldy #CopyingL |
251 sndinstr leax Help,pcr get instructions | 371 lbsr WritSOut write it to stdout |
252 bsr sndline send them | 372 ldx <wfileptr get pointer to file being copied |
253 exitok clrb | 373 ldy <wfilelen get file name length |
254 errexit os9 F$Exit | 374 lbsr WritSOut print file name |
255 | 375 leax >CopyTo,pcr print ' to ' |
256 sndline ldy #256 max chars to send | 376 ldy #CopyToL |
257 lda #1 std out | 377 lbsr WritSOut write it to stdout |
258 os9 I$WritLn write the line | 378 ldx <dstfptr get pointer to file being copied |
379 lbsr WrLine print file with CR | |
380 puls a restore dest path | |
381 GetOpts leax <optbuf,u point to option buffer | |
382 clrb was: ldb #SS.Opt | |
383 os9 I$GetStt get options | |
384 lbcs ShutDown branch if error | |
385 ldb ,x get device type | |
386 cmpb #DT.RBF rbf? | |
387 bne CopyLoop if not rbf device, don't get file size or fd seg | |
388 L04B4 lda <devtyp get device type | |
389 cmpa #DT.RBF rbf? | |
390 bne CopyLoop branch if not | |
391 pshs u save our statics ptr | |
392 lda <dstpath else get dest path | |
393 ldb #SS.Size and setstat option | |
394 ldx <srcflsiz get file size of source | |
395 ldu <srcflsiz+2 | |
396 os9 I$SetStt and set dest file to same size | |
397 lbcs ShutDown branch if error | |
398 puls u restore U | |
399 lda <dstpath get dest path | |
400 leax <fdbufcpy,u point to file desc. buffer | |
401 ldy #FD.SEG get size | |
402 ldb #SS.FD | |
403 os9 I$SetStt write src fd seg to dest file | |
404 * Copy loop is here | |
405 CopyLoop ldx <rdbufptr get ptr to read buffer | |
406 clra A = 0 = source prompt if needed | |
407 lbsr SwapDsk check for single disk copy and prompt if so | |
408 lda <srcpath get source path | |
409 ldy <bufsiz get buffer size | |
410 os9 I$Read read it! | |
411 bcs L0558 branch if error | |
412 lda #$01 A = 1 = dest prompt | |
413 lbsr SwapDsk check for single disk copy and prompt if so | |
414 lda <dstpath get dest path | |
415 os9 I$Write write it out! | |
416 lbcs ShutDown branch if error | |
417 lda <srcpath get source path | |
418 ldb #SS.EOF | |
419 os9 I$GetStt are we at end of file? | |
420 bcc CopyLoop branch if not | |
421 cmpb #E$EOF end of file error? | |
422 beq L0561 branch if so | |
423 L0558 cmpb #E$EOF end of file rror? | |
424 bne ShutDown branch if not | |
425 lda #$01 prompt destination flag | |
426 lbsr SwapDsk check for single drive copy and prompt if necessary | |
427 L0561 lda <dstpath get destination path | |
428 os9 I$Close close that file | |
429 bcs ShutDown branch if error | |
430 clr <dstpath else clear dest path | |
431 lda <srcpath get source path | |
432 os9 I$Close close it | |
433 bcs ShutDown branch if error | |
434 clr <srcpath clear src path | |
435 tst <wopt -w specified | |
436 lbeq ExitOk branch if not | |
437 lbra L03BE | |
438 | |
439 * Entry: X = ptr to data to write, Y = length | |
440 WritSOut lda #$01 standard out | |
441 os9 I$Write write it | |
259 rts | 442 rts |
260 | 443 |
261 * Send message and wait for disk switch for single drive copy | 444 PListErr leax >PLIncmp,pcr |
262 | 445 bsr WrLine |
263 destsnd lda #1 set flag for destination message | 446 bra ExitOk |
264 | 447 |
265 chkdrive tst <single are we doing single drive copy | 448 ShutDown pshs b |
266 beq msgrts nope..just exit | 449 lda <srcpath get source path |
267 pshs y,x else save registers | 450 beq L05AA branch if none |
268 | 451 os9 I$Close close it |
269 sndsrc pshs a save drive flag | 452 L05AA lda <dstpath get dest path |
270 tsta do we want source drive ? | 453 beq L05B1 branch if none |
271 bne snddst nope..do destination message | 454 os9 I$Close close it |
272 leax srcmsg,pcr point to 'source' msg | 455 L05B1 clr <srcpath clear source path |
273 ldy #srcmsgsz chars to send | 456 clr <dstpath and destination |
274 bra msgsnd go send it | 457 leax >CantCpy,pcr else show can't copy error |
275 | 458 ldy #CantCpyL |
276 srcmsg fcc /Ready SOURCE/ | 459 bsr WritSOut write out |
277 srcmsgsz equ *-srcmsg | 460 ldx <lstfopen show filename that failed |
278 | 461 ldy <lstfopln get length |
279 dstmsg fcc /Ready DESTINATION/ | 462 bsr WritSOut |
280 dstmsgsz equ *-dstmsg | 463 leax >SpcDsh,pcr |
281 | 464 ldy #SpcDshL |
282 cntmsg fcc /, hit C to continue: / | 465 bsr WritSOut write out |
283 cntmsgsz equ *-cntmsg | 466 puls b |
284 | 467 PrintErr os9 F$PErr print error |
285 | 468 tst <wopt -w used? |
286 snddst leax dstmsg,pcr point to 'destination' msg | 469 beq ExitOk branch if not |
287 ldy #dstmsgsz chars to send | 470 tst <abortflg abort flag set? |
288 | 471 bne ExitOk branch if so |
289 msgsnd lda #1 std out | 472 AskAgain leax >Cont,pcr point to continue prompt |
290 os9 I$Write write it | 473 ldy #ContL get length |
291 leax cntmsg,pcr point to 'hit C ...' | 474 bsr WritSOut write |
292 ldy #cntmsgsz get size of message | 475 clra ADDED +BGP+ |
293 os9 I$Write write it | 476 ldx <rdbufptr get pointer at readbuf |
294 leax ,-s back up for dummy buffer | 477 ldy #$0002 2 bytes |
295 ldy #1 chars to read | 478 os9 I$ReadLn read form stdin |
296 clra std in | 479 lda ,x get byte at X |
297 os9 I$Read read one char | 480 anda #$5F |
298 lda ,s+ | 481 cmpa #'Y user wants to continue? |
299 pshs y,x,a save registers | 482 lbeq L03BE branch if so |
300 leax crmsg,pcr point to <cr> | 483 cmpa #'N no? |
301 bsr sndline write it | 484 beq ExitOk branch if so |
302 puls y,x,a restore registers | 485 bra AskAgain else ask again |
303 eora #'C check if its a C | 486 |
304 anda #$DF make it upper case | 487 ShowHelp equ * |
305 puls a restore drive status | 488 IFNE DOHELP |
306 bne sndsrc loop back & send message | 489 leax >HlpMsg,pcr point to help message |
307 puls y,x restore registers | 490 ldy #HlpMsgL get length |
308 msgrts rts | 491 lda #$02 std error |
309 | 492 os9 I$WritLn write it |
310 Help fcc /Use: Copy <Path1> <Path2> [-s]/ | 493 ENDC |
311 fcb C$LF | 494 ExitOk clrb clear carry |
312 fcc / -s = single drive copy/ | 495 Exit os9 F$Exit and exit |
313 fcc / (Path2 must be complete pathlist)/ | 496 |
314 fcb C$CR | 497 * Write line passed in X |
315 crmsg fcb C$CR | 498 WrLine ldy #$00A0 |
316 | 499 WrNBytes lda #$01 |
317 emod | 500 os9 I$WritLn |
501 rts | |
502 | |
503 * Prompt User for Source or Destination Disk | |
504 SwapDsk tst <single single disk copy? | |
505 beq NoSwap branch if not | |
506 pshs y,x | |
507 L0626 pshs a | |
508 tsta | |
509 bne L0635 | |
510 leax >SrcPmpt,pcr point to source prompt | |
511 ldy #SrcPmptL get size | |
512 bra L063D write it and get input | |
513 L0635 leax >DstPmpt,pcr point to dest prompt | |
514 ldy #DstPmptL get size | |
515 L063D bsr WrNBytes write it | |
516 leax ,-s point to stack for temp buffer | |
517 ldy #$0001 one byte | |
518 clra from std in | |
519 os9 I$Read read byte from user | |
520 lda ,s+ get char | |
521 eora #'C | |
522 anda #$DF | |
523 beq L0657 branch if C | |
524 bsr L065E | |
525 puls a | |
526 bne L0626 | |
527 L0657 bsr L065E | |
528 puls a | |
529 puls y,x | |
530 NoSwap rts | |
531 L065E pshs y,x,a | |
532 lda #$01 | |
533 leax >CrRtn,pcr | |
534 ldy #80 | |
535 os9 I$WritLn | |
536 puls pc,y,x,a | |
537 | |
538 * StrLen | |
539 * | |
540 * Entry: | |
541 * X = ptr to string (space, comma or CR terminated) | |
542 * Exit: | |
543 * D = length of string | |
544 * X = ptr to byte after string | |
545 StrLen pshs u | |
546 ldu #$0000 | |
547 StrLenLp lda ,x+ | |
548 cmpa #C$SPAC | |
549 beq StrLenEx | |
550 cmpa #C$COMA | |
551 beq StrLenEx | |
552 cmpa #C$CR | |
553 beq StrLenEx | |
554 leau 1,u | |
555 bra StrLenLp | |
556 StrLenEx tfr u,d | |
557 puls u,pc | |
558 | |
559 * StrCpy | |
560 * | |
561 * Entry: | |
562 * X = ptr to src string | |
563 * Y = ptr to dest string | |
564 * Exit: | |
565 * D = number of bytes copied | |
566 * X = ptr to byte after original string | |
567 * X = ptr to byte after copied string | |
568 StrCpy pshs u | |
569 ldu #$0000 | |
570 CopyFnLp lda ,x+ | |
571 cmpa #C$SPAC | |
572 beq CopyFnEx | |
573 cmpa #C$COMA | |
574 beq CopyFnEx | |
575 cmpa #C$CR | |
576 beq CopyFnEx | |
577 sta ,y+ | |
578 leau 1,u | |
579 bra CopyFnLp | |
580 CopyFnEx tfr u,d | |
581 puls u,pc | |
582 | |
583 * Skip over spaces and commas | |
584 * | |
585 * Entry: | |
586 * X = ptr to string | |
587 * Exit: | |
588 * X = ptr to first non-whitespace char | |
589 * A = non-whitespace char | |
590 SkipSpcs lda ,x+ | |
591 cmpa #C$SPAC | |
592 beq SkipSpcs | |
593 cmpa #C$COMA | |
594 beq SkipSpcs | |
595 leax -1,x | |
596 rts | |
597 | |
598 * Skip over non-spaces and non-commas | |
599 * | |
600 * Entry: | |
601 * X = ptr to string | |
602 * Exit: | |
603 * X = ptr to first non-whitespace char | |
604 * A = non-whitespace char | |
605 SkipNSpc lda ,x+ | |
606 cmpa #C$SPAC | |
607 beq EatOut | |
608 cmpa #C$COMA | |
609 beq EatOut | |
610 cmpa #C$CR | |
611 bne SkipNSpc | |
612 EatOut leax -1,x | |
613 rts | |
614 | |
615 * Get source file in <srcfname and destination file in <dstfptr | |
616 GetSDFl leay <srcfname,u point X to next file pointer | |
617 bsr SrchFile skip white spaces, look for name on cmd line | |
618 bcs L067D branch if end | |
619 inc <srccnt else increment souce count | |
620 leay <dstfptr,u point Y to destination file | |
621 bsr SkipSpcs destroy any leading spaces | |
622 bsr SrchFile skip white spaces, look for name on cmd line | |
623 L067D rts | |
624 | |
625 * Starting at X, parse for a filename, skipping leading white spaces | |
626 SrchFile lda ,x | |
627 cmpa #C$CR CR? | |
628 beq L06A2 branch if so | |
629 stx ,y else store X at Y | |
630 SkipFile bsr SkipNSpc skip non-spaces | |
631 ParseOk clrb clear B | |
632 rts return | |
633 L06A2 tst <srccnt any file specified? | |
634 bne L06AA branch if so | |
635 BadPName ldb #E$BPNam else no source was specified | |
636 coma | |
637 rts | |
638 | |
639 L06AA ldx <srcfname get pointer | |
640 L06AC lda ,x+ get char | |
641 cmpa #C$SPAC space? | |
642 beq L06C4 branch if so | |
643 cmpa #C$COMA comma? | |
644 beq L06C4 branch if so | |
645 cmpa #C$CR carriage return? | |
646 beq L06C4 branch if so | |
647 cmpa #PDELIM pathlist delimiter? | |
648 bne L06AC branch if not | |
649 clr <srccnt else clear file count | |
650 stx ,y and store | |
651 bra L06AC continue parsing | |
652 L06C4 tst <srccnt file count 0? | |
653 beq L06D2 branch if so | |
654 tst <srcmode source mode? (exec or data dir) | |
655 beq BadPName branch if data | |
656 ldx <srcfname else get pointer | |
657 stx ,y save | |
658 bra ParseOk branch | |
659 L06D2 lda -$02,x | |
660 cmpa #PDELIM | |
661 beq BadPName | |
662 bra ParseOk | |
663 | |
664 emod | |
318 eom equ * | 665 eom equ * |
319 end | 666 end |