comparison CoCoOS9/level2v3/CMDS/copy.asm @ 31:bd2b07db8917 cocoos9lv2v3

CoCoOS9 version
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Jul 2018 15:16:13 +0900
parents
children
comparison
equal deleted inserted replaced
30:7b1b25ff010a 31:bd2b07db8917
1 ********************************************************************
2 * Copy - File copy utility
3 *
4 * $Id: copy.asm,v 1.1.1.1 2001/02/21 23:30:54 boisy Exp $
5 *
6 * Ed. Comments Who YY/MM/DD
7 * ------------------------------------------------------------------
8 * 10 Reworked RML
9
10 nam Copy
11 ttl File copy utility
12
13 * Edition 10 rewrite 10/28/88 - RML
14
15 ifp1
16 use defsfile
17 endc
18
19 tylg set Prgrm+Objct
20 atrv set ReEnt+rev
21 rev set $01
22 edition set 10
23
24 mod eom,name,tylg,atrv,start,size
25
26 inpath rmb 1 input path number
27 outpath rmb 1 output path number
28 indevtyp rmb 1 input device type (1 = RBF)
29 verify rmb 1 verify on/off (1=on)
30 bufsize rmb 2 read/write buffer size
31 fsizemsb rmb 2 msb's of file size
32 fsizelsb rmb 2 lsb's of file size
33 writemsb rmb 2 msb's of bytes written to output
34 writelsb rmb 2 lsb's of bytes written to output
35 single rmb 1 single drive copy flag (1=yes)
36 attribs rmb 1 file attributes
37 fdbuff rmb 16 File Descriptor buffer
38 optbuff rmb 32 Path Descriptor Options Buffer
39 stack rmb 448 stack storage
40 vfybuff rmb 256 verify buffer
41 buffer rmb $2000-. read/write buffer (minimum..will expand with mem mod)
42 size equ .
43
44 name fcs /Copy/
45 fcb edition
46
47 start leas vfybuff,u set stack pointer to 512
48 pshs u save u reg
49 leau <optbuff,u point u to 20th byte
50
51 clearit clr ,-u clear byte
52 cmpu ,s done ?
53 bhi clearit loop back
54 tfr y,d move in top of mem (after param area)
55 subd ,s++ subtract current stack
56 subd #$0300 and back off variable storage
57 clrb round off to page bondary
58 std <bufsize buffer size
59 pshs x save x register
60
61 getopt lda ,x+ get a char
62 cmpa #'- was it a '-'??
63 beq chkopt yes..go check opt
64 cmpa #C$CR was it a <cr>??
65 bne getopt no..check next char
66 bra openin else done..go finish processing
67
68 chkopt ldd ,x+ get next 2 chars
69 eora #'S check if its an S
70 anda #$DF make upper case
71 lbne sndinstr not an s.. send instructions
72 cmpb #$30 else check if next char is number or letter
73 lbhs sndinstr yup...send instructions
74 inc <single set s option
75 bra getopt and check next char
76
77 openin puls x restore line pointer
78 lda #READ. open first file
79 os9 I$Open
80 lbcs chkerr error..go see what it was
81 sta <inpath save path number
82 pshs x save second path name start
83 leax <fdbuff,u point to FD buffer
84 ldy #16 bytes to read
85 ldb #SS.FD get file descriptor
86 os9 I$GetStt
87 puls x restore line pointer
88 bcs getintyp skip this on eror
89 tst <single single drive copy ?
90 beq getintyp no..skip this stuff
91 lda ,x get first char of path name
92 ldb #E$BPNam load bad path name error message
93 cmpa #'/ was it a path separaor ?
94 bne errjump nope..error
95
96 getintyp pshs x save out path name start
97 lda <inpath get path number
98 bsr getopts get option section
99 lda ,x get device type
100 sta <indevtyp save it
101 ldb #$0F default attributes...read,write,execute,public
102 cmpa #DT.RBF was device type RBF ?
103 bne openout nope...don't get file size/attributes
104 pshs u,x save registers
105 lda <inpath get path number
106 ldb #SS.Size Get File size
107 bsr getstat do the GetStt call..exit on error
108 stx <fsizemsb save 2 msb's of file size
109 stu <fsizelsb save 2 lsb's of file size
110 puls u,x restore registers
111 ldb <$13,x get file attributes
112
113 openout stb <attribs save attributes
114 ldx ,s get start of second path name
115 lbsr destsnd send destination msg
116 lda #UPDAT. open file for update
117 ldb <attribs get attributes
118 os9 I$Create create the file
119 puls x restore x register
120 bcc open010 no error..skip this
121 inc <verify set verify off
122 lda #WRITE. open filein write only mode
123 ldb <attribs get atributes
124 os9 I$Create create the file
125 bcs errjump exit on error
126
127 open010 sta <outpath save second path number
128 bsr getopts get option section
129 ldb ,x get device type
130 cmpb #DT.RBF was it RBF
131 beq setvfy yup...skip this
132 inc <verify set verify off
133 bra mainloop and skip all this
134
135 errjump lbra errexit nope....error
136
137 getopts leax <optbuff,u point to buffer
138 ldb #SS.Opt get option section of path descritor
139
140 getstat os9 I$GetStt
141 bcs errjump exit on error
142 rts
143
144 setvfy tst <verify do we want verify on
145 bne setsiz nope...dont set driver verify on
146 ldb #1 verify
147 stb 8,x turn verify on
148 ldb #SS.OPT set options
149 os9 I$SetStt
150 bcs errjump exit on error
151
152 setsiz lda <indevtyp get device type
153 cmpa #DT.RBF is it an RBF file
154 bne mainloop nope...dont preset file size
155 pshs u save register
156 lda <outpath get out path number
157 ldb #SS.Size set file size
158 ldx <fsizemsb get 2 msb's of in file size
159 ldu <fsizelsb get 2 lsb's of in file size
160 os9 I$SetStt set the size
161 bcs errjump exit on error
162 puls u restore register
163 lda <outpath get out path number
164 leax <fdbuff,u point to FD buffer
165 ldy #16 number of bytes to write
166 ldb #SS.FD write out the FD (for dates,etc.)
167 os9 I$SetStt
168
169 mainloop leax buffer,u point to buffer
170 clra source drive code
171 lbsr chkdrive send source switch msg
172 lda <inpath get in path number
173 ldy <bufsize get buffer size
174 os9 I$Read read a block
175 bcs chkeof2 if error..go check which one
176 lbsr destsnd send destination switch msg
177 lda <outpath get out path number
178 os9 I$Write write the block out
179 bcs errjump exit on error
180 tst <verify are we verifying ?
181 bne chkeof skip this
182 pshs u,y save registers
183 ldx <writemsb get 2 msb's of last write
184 ldu <writelsb get 2 lsb's of last write
185 lda <outpath get out path number
186 os9 I$Seek
187 bcs errjump exit on error
188 ldu 2,s get original u back
189 leau buffer,u point to buffer start
190 ldd ,s get bytes written
191 addd <writelsb add on to current 2 lsb positions
192 std <writelsb save them
193 ldd ,s get bytes written
194 bcc vfy000 skip if no carry
195 leax 1,x bump up 2 msb's
196 stx <writemsb and save them
197
198 vfy000 ldy #$0100 chars to read for verify
199 std ,s save it
200 tsta did we write more than 255 bytes ?
201 bne vfy010 yes...only read 256
202 tfr d,y else xfer amount we did write
203
204 vfy010 ldx 2,s get u register
205 leax $200,x point to start of verify buffer
206 lda <outpath get output path number
207 os9 I$Read read a block in
208 bcs errexit exit on error
209
210 vfy020 lda ,u+ get char from in buffer
211 cmpa ,x+ get char from out buffer
212 bne snderr1 not equal...send write verfiy msg
213 leay -1,y decrement read count
214 bne vfy020 if more..loop back
215 ldd ,s get write count back
216 subd #$0100 subtract verify buffer size
217 bhi vfy000 if more left...loop back
218 puls u,y else restore registers
219
220 chkeof lda <inpath get in path number
221 ldb #SS.EOF check for end of file
222 os9 I$GetStt
223 bcc mainloop nope...loop back
224 cmpb #E$EOF are we at end of file ?
225 beq closeout yes...close file
226
227
228 chkeof2 cmpb #E$EOF check for end of file
229 bne errexit nope...error exit
230 bsr destsnd send msg for disk switch
231
232 closeout lda <outpath get out path number
233 os9 I$Close close the file
234 bcc exitok exit w/o error if o.k.
235 bra errexit else error exit
236
237 errmsg1 fcb $07
238 fcc /Error - write verification failed./
239 fcb $0D
240
241 snderr1 leax errmsg1,pcr address of 'write verify failed' msg
242 bsr sndline send it
243 comb set carry
244 ldb #$01 set error
245 bra errexit exit
246
247 chkerr cmpb #E$BPNam was it bad path name
248 bne errexit error exit
249
250 sndinstr leax Help,pcr get instructions
251 bsr sndline send them
252 exitok clrb
253 errexit os9 F$Exit
254
255 sndline ldy #256 max chars to send
256 lda #1 std out
257 os9 I$WritLn write the line
258 rts
259
260 * Send message and wait for disk switch for single drive copy
261
262 destsnd lda #1 set flag for destination message
263
264 chkdrive tst <single are we doing single drive copy
265 beq msgrts nope..just exit
266 pshs y,x else save registers
267
268 sndsrc pshs a save drive flag
269 tsta do we want source drive ?
270 bne snddst nope..do destination message
271 leax srcmsg,pcr point to 'source' msg
272 ldy #srcmsgsz chars to send
273 bra msgsnd go send it
274
275 srcmsg fcc /Ready SOURCE/
276 srcmsgsz equ *-srcmsg
277
278 dstmsg fcc /Ready DESTINATION/
279 dstmsgsz equ *-dstmsg
280
281 cntmsg fcc /, hit C to continue: /
282 cntmsgsz equ *-cntmsg
283
284
285 snddst leax dstmsg,pcr point to 'destination' msg
286 ldy #dstmsgsz chars to send
287
288 msgsnd lda #1 std out
289 os9 I$Write write it
290 leax cntmsg,pcr point to 'hit C ...'
291 ldy #cntmsgsz get size of message
292 os9 I$Write write it
293 leax ,-s back up for dummy buffer
294 ldy #1 chars to read
295 clra std in
296 os9 I$Read read one char
297 lda ,s+
298 pshs y,x,a save registers
299 leax crmsg,pcr point to <cr>
300 bsr sndline write it
301 puls y,x,a restore registers
302 eora #'C check if its a C
303 anda #$DF make it upper case
304 puls a restore drive status
305 bne sndsrc loop back & send message
306 puls y,x restore registers
307 msgrts rts
308
309 Help fcc /Use: Copy <Path1> <Path2> [-s]/
310 fcb C$LF
311 fcc / -s = single drive copy/
312 fcc / (Path2 must be complete pathlist)/
313 fcb C$CR
314
315 crmsg
316 fcb C$CR
317
318 emod
319 eom equ *
320 end