0
|
1 ********************************************************************
|
|
2 * PipeMan - Pipe file manager
|
|
3 *
|
|
4 * $Id$
|
|
5 *
|
|
6 * Ed. Comments Who YY/MM/DD
|
|
7 * ------------------------------------------------------------------
|
|
8 * 4 Original OS-9 L2 Tandy distribution
|
|
9 * Added comments from Curtis Boyle's code BGP 98/10/22
|
|
10
|
|
11 nam PipeMan
|
|
12 ttl Pipe file manager
|
|
13
|
|
14 ifp1
|
|
15 use defsfile
|
|
16 use pipedefs
|
|
17 endc
|
|
18
|
|
19 rev set $01
|
|
20 edition set 4
|
|
21
|
|
22 mod eom,Name,FlMgr+Objct,ReEnt+rev,Start,0
|
|
23
|
|
24 Name fcs /PipeMan/
|
|
25 fcb edition
|
|
26
|
|
27 Start lbra Create Create, same as open
|
|
28 lbra Open Open
|
|
29 lbra UnkSvc MakDir
|
|
30 lbra UnkSvc ChgDir
|
|
31 lbra UnkSvc Delete
|
|
32 lbra L0040 Seek
|
|
33 lbra PRead PRead
|
|
34 lbra PWrite PWrite
|
|
35 lbra L00AB PRdLn
|
|
36 lbra L0105 PWrLn
|
|
37 lbra L0040 GetStat
|
|
38 lbra L0040 SetStat
|
|
39 lbra Close Return to system
|
|
40
|
|
41 UnkSvc comb Exit with Unknown Service error
|
|
42 ldb #E$UnkSvc
|
|
43 rts
|
|
44
|
|
45 L0040 clrb No error & return
|
|
46 rts
|
|
47
|
|
48 * Open or create a Pipe
|
|
49 Create
|
|
50 Open ldu PD.RGS,y get Caller's register stack ptr
|
|
51 ldx R$X,u get pointer to pathname
|
|
52 pshs y preserve descriptor pointer
|
|
53 os9 F$PrsNam is it legal?
|
|
54 bcs L007B no, exit with error
|
|
55 ldx <D.Proc get task #
|
|
56 ldb P$Task,x
|
|
57 leax -1,y point to last character of pathname
|
|
58 os9 F$LDABX get it
|
|
59 tsta high bit terminated?
|
|
60 bmi L0060 yes, go on
|
|
61 leax ,y point just past it
|
|
62 os9 F$PrsNam parse it again
|
|
63 bcc L007B can't accept more data, return error
|
|
64 L0060 sty R$X,u save updated path pointer to caller
|
|
65 puls y restore path dsc. ptr
|
|
66 ldd #256 grab a page of memory for my buffer
|
|
67 os9 F$SRqMem
|
|
68 bcs L007A can't get memory, return error
|
|
69 stu PD.BUF,y save pointer to buffer
|
|
70 stu <PD.NxtI,y save read pointer?
|
|
71 stu <PD.NxtO,y save write pointer?
|
|
72 leau d,u point to end of buffer
|
|
73 stu <PD.End,y save the end pointer
|
|
74 L007A rts return
|
|
75 L007B comb Exit with Bad Pathname error
|
|
76 ldb #E$BPNam
|
|
77 puls y,pc
|
|
78
|
|
79 * Close
|
|
80 Close lda PD.CNT,y any open images left?
|
|
81 bne L008E yes, go on
|
|
82 ldu PD.BUF,y No, get buffer pointer
|
|
83 ldd #256 return it's memory to system
|
|
84 os9 F$SRtMem
|
|
85 bra L00A9
|
|
86 * Still stuff open to pipe
|
|
87 * Check Read part of pipe
|
|
88 L008E cmpa PD.RCT,y Same as # images open to Read from pipe?
|
|
89 bne L0096 No, go check Write images
|
|
90 leax PD.RPID,y Point to Read variables
|
|
91 bra L009C Send signal to reading process
|
|
92 * Check Write part of pipe
|
|
93 L0096 cmpa PD.WCT,y Same as # images open to Write to pipe?
|
|
94 bne L00A9 No, exit without error
|
|
95 leax PD.WPID,y Point to Write variables
|
|
96
|
|
97 * Send signal
|
|
98 L009C lda ,x Get Process # to send signal to
|
|
99 beq L00A9 None, exit without error
|
|
100 ldb 2,x get the signal code to send
|
|
101 beq L00A9 None, exit without error
|
|
102 clr 2,x Clear out signal code
|
|
103 os9 F$Send Send to process
|
|
104 L00A9 clrb No error & exit
|
|
105 rts
|
|
106
|
|
107 * ReadLn entry point
|
|
108 * Entry: Y=Path dsc. ptr
|
|
109 L00AB ldb #$0D Flag for ReadLn
|
|
110 stb PD.REOR,y Save as Not raw flag in Read area
|
|
111 bra L00B3 Go read
|
|
112
|
|
113 * Read entry point
|
|
114 PRead clr PD.REOR,y Raw mode on
|
|
115 L00B3 leax PD.RPID,y point to Pipe Read variables
|
|
116 lbsr L0160 Go wait for pipe to be ready for us
|
|
117 bcs L0100 Error, shut off our side & signal other end of pipe
|
|
118 ldd R$Y,u get # bytes requested to read
|
|
119 beq L0100 None, shut off our side & signal other end of pipe
|
|
120 ldx R$X,u get pointer to callers destination
|
|
121 addd R$X,u
|
|
122 pshs b,a
|
|
123 pshs x preserve start pointer
|
|
124 bra L00D5
|
|
125
|
|
126 * Read Loop for both ReadLn (stops on CR) or Read (stops when size is done)
|
|
127
|
|
128 L00C8 pshs x Preserve buffer start ptr
|
|
129 leax PD.RPID,y Point to Read vars
|
|
130 lbsr L018B Go wait for possible data
|
|
131 bcc L00D5 May be some, continue
|
|
132 puls x Restore buffer start ptr
|
|
133 bra L00F1 None expected, exit with what we have
|
|
134
|
|
135 L00D5 ldx <D.Proc Get current process ptr
|
|
136 ldb P$Task,x Get task #
|
|
137 puls x Get Buffer start ptr
|
|
138
|
|
139 * Read from pipe buffer
|
|
140 L00DB lbsr L01F2
|
|
141 bcs L00C8
|
|
142 os9 F$STABX Got byte, save it to caller
|
|
143 leax 1,x Bump buffer ptr up
|
|
144 tst PD.REOR,y Check Read/ReadLn flag
|
|
145 beq L00ED Raw, skip ahead
|
|
146 cmpa PD.REOR,y Was the byte received a CR?
|
|
147 beq L00F1 Yes, done reading
|
|
148 L00ED cmpx ,s Hit end of buffer read requested yet?
|
|
149 bcs L00DB No, keep reading
|
|
150 L00F1 tfr x,d Move ptr to D
|
|
151 subd ,s++ Calculate actual size read
|
|
152 addd R$Y,u ??? Add to size previously read???
|
|
153 std R$Y,u Save total # bytes read to caller
|
|
154 bne L00FF If some read, skip ahead
|
|
155 ldb #E$EOF Otherwise, exit with EOF error
|
|
156 bra L0100
|
|
157 L00FF clrb No error
|
|
158
|
|
159 L0100 leax PD.RPID,y Point to pipe Read vars
|
|
160 lbra L01BD
|
|
161
|
|
162 L0105 ldb #$0D Flag for WritLn (and terminator for lines)
|
|
163 stb <PD.WEOR,y
|
|
164 bra L010F Go do the write
|
|
165
|
|
166 PWrite clr <PD.WEOR,y Flag for Raw Write
|
|
167 L010F leax PD.WPID,y Point to Write variables
|
|
168 lbsr L0160 Go wait for pipe to be ready for us
|
|
169 bcs L015C Error, shut off our side & signal other end of pipe
|
|
170 ldd R$Y,u Get requested size to Write
|
|
171 beq L015C None, shut off our side & signal other end of pipe
|
|
172 ldx R$X,u Get ptr to data to write
|
|
173 addd R$X,u Calculate end of data ptr
|
|
174 pshs b,a
|
|
175 pshs x Preserve start ptr
|
|
176 bra L0131 Start writing
|
|
177 L0124 pshs x Preserve current buffer ptr
|
|
178 leax PD.WPID,y Point to Write vars
|
|
179 lbsr L018B Go wait for data to be ready
|
|
180 bcc L0131 Ready, go try writing again
|
|
181 puls x No more data, restore buffer ptr
|
|
182 bra L0150 Go write out as much as we got
|
|
183
|
|
184 L0131 ldx <D.Proc Get process dsc. ptr
|
|
185 ldb P$Task,x Get task #
|
|
186 puls x Get start ptr back
|
|
187 L0137 os9 F$LDABX Get byte from caller
|
|
188 lbsr L01CC
|
|
189 bcs L0124
|
|
190 leax 1,x
|
|
191 tst <PD.WEOR,y
|
|
192 beq L014B
|
|
193 cmpa <PD.WEOR,y
|
|
194 beq L0150
|
|
195 L014B cmpx ,s Hit end of buffer?
|
|
196 bcs L0137 No, keep writing
|
|
197 clrb Yes, no error
|
|
198 L0150 pshs b,cc Preserve error status
|
|
199 tfr x,d Move buffer ptr to D
|
|
200 subd 2,s Calculate size actually written
|
|
201 addd R$Y,u Add to size previously written
|
|
202 std R$Y,u Save for caller
|
|
203 puls x,b,cc Restore error status
|
|
204 L015C leax PD.WPID,y Point to Write vars
|
|
205 bra L01BD Shut off Write part, send signal to Read part
|
|
206
|
|
207 * Make current process the process to Read or Write from Pipe, or wait in line
|
|
208 * until pipe is ready to for our process
|
|
209 * Entry: Y=Path dsc. ptr
|
|
210 * X=Ptr to either Pipe Read or Pipe Write variables
|
|
211 L0160 lda ,x Get process # that is reading or writing to pipe
|
|
212 beq L0185 If none, make the current process the one
|
|
213 cmpa PD.CPR,y Same as current process using this path?
|
|
214 beq L0189 Yes, no error & exit
|
|
215 * A read or write request from the pipe was made from a process that is not
|
|
216 * listed in the PD.??? pipe vars
|
|
217 inc 1,x New process using pipe, update # processes using
|
|
218 ldb 1,x Get new # of process reading or writing
|
|
219 cmpb PD.CNT,y Same as total # of processes using pipe?
|
|
220 bne L0173 No, skip ahead
|
|
221 lbsr L009C Yes, send signal from 2,x to process using pipe
|
|
222 * New process is put in line to read/write to/from pipe
|
|
223 L0173 os9 F$IOQu Stick waiting process (A) into I/O Queue
|
|
224 dec 1,x Dec # images in pipe down again
|
|
225 pshs x Preserve ptr
|
|
226 ldx <D.Proc Get current process dsc. ptr
|
|
227 ldb <P$Signal,x Get last signal code from current process
|
|
228 puls x Get ptr back
|
|
229 beq L0160 If it didn't receive the signal, try again
|
|
230 coma Set carry & exit
|
|
231 rts
|
|
232
|
|
233 L0185 ldb PD.CPR,y Get Current process #
|
|
234 stb ,x Save as process # that is reading/writing to pipe
|
|
235 L0189 clrb No error & exit
|
|
236 rts
|
|
237
|
|
238 L018B ldb 1,x Get # images [reading or writing] from pipe?
|
|
239 incb Base 1
|
|
240 cmpb PD.CNT,y Same as # of open images?
|
|
241 beq L01B9 Yes, Exit with Write Error
|
|
242 stb 1,x Save updated # images
|
|
243 ldb #$01 Wakeup signal
|
|
244 stb 2,x Save as signal to send to process
|
|
245 clr PD.CPR,y Clear out current process # using pipe
|
|
246 pshs x Preserve read/write offset ptr
|
|
247 tfr x,d Move to D
|
|
248 eorb #$04 Flip between read/write vars
|
|
249 tfr d,x Move to X
|
|
250 lbsr L009C Go send signal to process on other end of pipe
|
|
251 ldx #$0000 Shut off process until signal received
|
|
252 os9 F$Sleep
|
|
253 ldx <D.Proc Get current process
|
|
254 ldb <P$Signal,x Get last signal code received
|
|
255 puls x Restore read/write offset ptr
|
|
256 dec 1,x Dec # open images
|
|
257 tstb Was there a signal receieved?
|
|
258 bne L01BB Yes, exit with carry set
|
|
259 clrb No error & exit
|
|
260 rts
|
|
261 L01B9 ldb #E$Write Write error
|
|
262 L01BB coma
|
|
263 rts
|
|
264 * Shut off Read part, send signal to Write part
|
|
265 * Shut down our side of pipe & send signal to other half of pipe
|
|
266 L01BD pshs u,b,cc Preserve U, error code & status
|
|
267 clr ,x Clear out process # using part of pipe
|
|
268 tfr x,d Move ptr to D
|
|
269 eorb #$04 Flip between read/write vars
|
|
270 tfr d,x Move to X
|
|
271 lbsr L009C Send Signal to process on other end of pipe
|
|
272 puls pc,u,b,cc Restore error status & return
|
|
273
|
|
274 * Entry: X=Ptr within caller's area we are writing from
|
|
275 * A=Char to write
|
|
276 * B=Task # of caller
|
|
277 L01CC pshs x,b Preserve ptr & Task #
|
|
278 ldx <PD.NxtI,y Get ptr to next char in pipe buffer
|
|
279 ldb <PD.RFlg,y Get data ready in pipe buffer flag
|
|
280 beq L01DE No data ready, skip ahead
|
|
281 cmpx <PD.NxtO,y Meeting write buffer ptr?
|
|
282 bne L01E3 No, continue
|
|
283 comb
|
|
284 puls pc,x,b
|
|
285 * Put char into pipe buffer & Set flag that data is ready
|
|
286 * Entry: Y=Path dsc. ptr
|
|
287 * A=Char to put in buffer
|
|
288 L01DE ldb #1 Set flag
|
|
289 stb <PD.RFlg,y Save it
|
|
290 L01E3 sta ,x+ Save char in pipe buffer
|
|
291 cmpx <PD.End,y Hit end of buffer?
|
|
292 bcs L01EC No, continue
|
|
293 ldx PD.BUF,y Yes, wrap to beginning
|
|
294 L01EC stx <PD.NxtI,y Save current position in buffer
|
|
295 clrb
|
|
296 puls pc,x,b Restore regs
|
|
297 L01F2 lda <Pd.RFlg,y
|
|
298 bne L01F9
|
|
299 comb
|
|
300 rts
|
|
301 L01F9 pshs x
|
|
302 ldx <PD.NxtO,y
|
|
303 lda ,x+
|
|
304 cmpx <PD.END,y
|
|
305 bcs L0207
|
|
306 ldx PD.BUF,y
|
|
307 L0207 stx <PD.NxtO,y
|
|
308 cmpx <PD.NxtI,y
|
|
309 bne L0212
|
|
310 clr <Pd.RFlg,y
|
|
311 L0212 andcc #^Carry
|
|
312 puls pc,x
|
|
313
|
|
314 emod
|
|
315 eom equ *
|
|
316 end
|
|
317
|
|
318
|