747
|
1 ********************************************************************
|
|
2 * OS9p3 - Printerr functionality for Level II
|
|
3 *
|
|
4 * $Id$
|
|
5 *
|
|
6 * Peter E. Durham
|
|
7 * The New Wentworth Timesharing System
|
|
8 * summer: 6 Twin Brook Circle school: Quincy House D-24
|
|
9 * Andover, MA 01810 58 Plympton St.
|
|
10 * (617) 475-4243 Cambridge, MA 02138
|
|
11 * (617) 498-3209
|
|
12 * cis: 73177,1215 delphi: PEDXING
|
|
13 * unix: harvard!husc4!durham_2 intnet: durham_2@husc4.harvard.edu
|
|
14 *
|
|
15 * COPYRIGHT (C) 1987 by Peter Durham
|
|
16 * Permission is given to all members of the OS-9 community to use,
|
|
17 * modify, and share this program for their personal enjoyment.
|
|
18 * Commercial use of this program, which was written for fun to share with
|
|
19 * the community, is prohibited without the consent of the author.
|
|
20 * Please share any extensions or modifications with the author, who
|
|
21 * would be interested in hearing about them.
|
|
22 *
|
|
23 * NOTE
|
|
24 * Quick poll... how does the above sound as a copyright notice? Clearly,
|
|
25 * authors like to share their work while maintaining some control on it.
|
|
26 * And it doesn't seem fair for someone else to make $ from something
|
|
27 * someone else made for fun. I think the above conditions are what most
|
|
28 * people want. Let me know what you think.
|
|
29 *
|
|
30 * NOTE
|
|
31 * The inspiration for this utility was the os9p3 example in
|
|
32 * the Tandy Level II manual. Tandy deserves praise for
|
|
33 * including examples such as this one in their manuals.
|
|
34 *
|
|
35 * NOTE
|
|
36 * There is something funny about OS9p3 modules... some versions
|
|
37 * are not liked, others are. When developing this module, often
|
|
38 * a version would fail... but if I added a "leas 0,s" right before
|
|
39 * the "rts" in PrinBuf, it would work! Probably the location and
|
|
40 * operation are not significant. This version here has never failed
|
|
41 * to boot on my system; however, if it does on yours (or you change
|
|
42 * it), try putting such things in.
|
|
43 *
|
|
44 * NOTE
|
|
45 * For those people who just can't have enough... OS9p3 will look for
|
|
46 * a module called OS9p4, and link to it, and execute it. Thanks to
|
|
47 * Kev for this idea. Now we can keep additions to the kernel in nice
|
|
48 * separate chunks. (How long 'til OS9p11 comes around...?)
|
|
49 *
|
|
50 * Ed. Comments Who YY/MM/DD
|
|
51 * ------------------------------------------------------------------
|
|
52 * 1 First release PED 87/06/23
|
|
53 nam OS9p3
|
|
54 ttl Printerr functionality for Level II
|
|
55
|
|
56 ifp1
|
|
57 use defsfile
|
|
58 endc
|
|
59
|
|
60 type set Systm ;System module, 6809 object code
|
1289
|
61 revs set 0 ;
|
747
|
62 edition set 1
|
|
63
|
1289
|
64 mod eom,name,type,ReEnt+revs,entry,256
|
747
|
65
|
|
66 name fcs "OS9p3"
|
|
67 fcb edition
|
|
68
|
|
69 *+
|
|
70 * Initialization routine and table
|
|
71 *-
|
|
72 Entry equ *
|
|
73 leay SvcTbl,pcr ;Get address of table
|
|
74 os9 F$SSvc ;Install services in table
|
|
75 lda #Type ;Get system module type for OS9p4
|
|
76 leax P4Name,pcr ;Get name for OS9p4
|
|
77 os9 F$Link ;Try to link to it
|
|
78 bcs Exit ;If not found, exit
|
|
79 jsr ,y ;Go execute it!
|
|
80 Exit rts ;Return to os9p2
|
|
81
|
|
82 SvcTbl equ *
|
|
83 fcb F$PErr ;System call number
|
|
84 fdb PErr-*-2 ;Offset to code
|
|
85 fcb $80 ;End of table
|
|
86
|
|
87 *+
|
|
88 * The new F$Perr service call
|
|
89 *-
|
|
90 *+
|
|
91 * Data (in user space!)
|
|
92 *-
|
|
93 BufLen equ 80
|
|
94 Buf rmb BufLen
|
|
95 HunDig equ Buf+7
|
|
96 TenDig equ Buf+8
|
|
97 OneDig equ Buf+9
|
|
98 DataMem equ .
|
|
99
|
|
100 *+
|
|
101 * FUNCTION PErr
|
|
102 * PURPOSE Top level routine
|
|
103 * REGISTERS B = Error code (after Setup)
|
|
104 * U = User memory area (after Setup)
|
|
105 * Y = User process descriptor (after Setup)
|
|
106 * A = Error file path number (after OpenFil)
|
|
107 * X = Pointer to strings
|
|
108 *-
|
|
109 PErr equ *
|
|
110 bsr Setup ;Go set up registers
|
|
111 leax ErrMsg,pcr ;Get pointer to "Error #000"
|
|
112 bsr MoveBuf ;Go copy it over
|
|
113 bsr WritNum ;Go copy the number into it
|
|
114 lbsr PrinMsg ;Go print the message
|
|
115 bcs PErrBye ;If error, abort
|
|
116 leax FilNam,pcr ;Get pointer to "/dd/sys/errmsg"
|
|
117 bsr MoveBuf ;Go copy it over
|
|
118 lbsr OpenFil ;Go open the file
|
|
119 bcs PErrBye ;If error, abort
|
|
120 Loop lbsr RdBuf ;Go read a line from the file
|
|
121 bcs Error ;If error, print CR, and abort
|
|
122 pshs b ;Save error code
|
|
123 pshs b ;Save error code again for compare
|
|
124 bsr CalcNum ;What number is on this line?
|
|
125 cmpb ,s+ ;Is this line the right line?
|
|
126 puls b ;Restore error code
|
|
127 bne Loop ;If not right line, loop again
|
|
128 lbsr PrinBuf ;If right line, write line out
|
|
129 bra Close ;Done, so close the file
|
|
130 Error lbsr DoCR ;Go print a carriage return
|
|
131 Close lbsr ClosFil ;Go close the file
|
|
132 PErrBye rts ;Return from system call
|
|
133
|
|
134 *+
|
|
135 * FUNCTION SetUp
|
|
136 * PURPOSE Sets up registers
|
|
137 * GIVES B = Error code
|
|
138 * U = Pointer to data memory on user stack in user space
|
|
139 * Y = Pointer to user process descriptor in system space
|
|
140 *-
|
|
141 SetUp equ *
|
|
142 ldb R$B,u ;Get error code
|
|
143 ldy D.Proc ;Get user's process descriptor
|
|
144 ldu P$SP,y ;Get user's stack pointer
|
|
145 leau -DataMem,u ;Reserve a little space
|
|
146 rts
|
|
147
|
|
148 *+
|
|
149 * FUNCTION MoveBuf
|
|
150 * PURPOSE Copies string to user space
|
|
151 * TAKES X = location of string in system space
|
|
152 *-
|
|
153 MoveBuf equ *
|
|
154 pshs u,y,d ;Save registers
|
|
155 lda D.SysTsk ;Get system process task number
|
|
156 ldb P$Task,y ;Get user process task number
|
|
157 leau Buf,u ;Get pointer to destination buffer
|
|
158 ldy #BufLen ;Copy BufLen characters over (extras, oh well)
|
|
159 os9 F$Move ;Move string to user space
|
|
160 puls d,y,u,pc ;Restore registers and return
|
|
161
|
|
162 *+
|
|
163 * FUNCTION WriteNum
|
|
164 * PURPOSE Puts the ASCII value of the error code in user space
|
|
165 * TAKES B = error code
|
|
166 *-
|
|
167 WritNum equ *
|
|
168 pshs x,d ;Save registers
|
|
169 clra ;Start A as 0
|
|
170 Huns cmpb #100 ;Is B >= 100?
|
|
171 blo HunDone ;If not, go do Tens
|
|
172 inca ;Increment hundreds digit
|
|
173 subb #100 ;Subtract 100 from B
|
|
174 bra Huns ;Go do again
|
|
175 HunDone leax HunDig,u ;Where to put digit
|
|
176 bsr WritDig ;Go put it there
|
|
177 clra ;Start A again as 0
|
|
178 Tens cmpb #10 ;Is B >= 10?
|
|
179 blo TenDone ;If not, go do Ones
|
|
180 inca ;Increment hundreds digit
|
|
181 subb #10 ;Subtract 10 from B
|
|
182 bra Tens ;Go do again
|
|
183 TenDone leax TenDig,u ;Where to put digit
|
|
184 bsr WritDig ;Go put it there
|
|
185 tfr b,a ;Get ones digit
|
|
186 leax OneDig,u ;Where to put digit
|
|
187 bsr WritDig ;Go put it there
|
|
188 puls d,x,pc ;Restore registers and return
|
|
189
|
|
190 *+
|
|
191 * FUNCTION WritDig
|
|
192 * PURPOSE Copy digit into user space
|
|
193 * TAKES A = digit to copy (not in ASCII yet)
|
|
194 * X = where to put digit
|
|
195 *-
|
|
196 WritDig equ *
|
|
197 pshs d ;Save registers
|
|
198 adda #'0 ;Convert A to ASCII
|
|
199 ldb P$Task,y ;Get task number
|
|
200 os9 F$StABX ;Write that digit to user space
|
|
201 puls d,pc ;Restore registers and return
|
|
202
|
|
203 *+
|
|
204 * FUNCTION CalcNum
|
|
205 * PURPOSE Converts ASCII number in user space to binary
|
|
206 * TAKES Buf (in user space) = ASCII number
|
|
207 * GIVES B = number converted
|
|
208 * X = points to first nonnumeric character
|
|
209 *-
|
|
210 CalcNum equ *
|
|
211 pshs a ;Save register
|
|
212 leax Buf,u ;Get pointer to buffer
|
|
213 clrb ;Set accumulator to zero
|
|
214 NextDig bsr LoadDig ;Get digit from user space
|
|
215 suba #'0 ;Convert to binary; is it less than zero?
|
|
216 bmi CalcBye ;If so, return
|
|
217 cmpa #9 ;Is the digit more than nine?
|
|
218 bhi CalcBye ;If so, return
|
|
219 pshs a ;Save the digit while we multiply
|
|
220 lda #10 ;Multiply current number by 10
|
|
221 mul ;Do it
|
|
222 addb ,s+ ;Add new digit to number
|
|
223 leax 1,x ;Advance X to next digit
|
|
224 bra NextDig ;Go get the next digit
|
|
225 CalcBye puls a,pc ;Restore register and return
|
|
226
|
|
227 *+
|
|
228 * FUNCTION LoadDig
|
|
229 * PURPOSE Get digit from user space
|
|
230 * TAKES X = pointer to digit in user space
|
|
231 * GIVES A = digit in user space
|
|
232 *-
|
|
233 LoadDig equ *
|
|
234 pshs b ;Save register
|
|
235 ldb P$Task,y ;Get user process task number
|
|
236 os9 F$LdABX ;Get digit
|
|
237 puls b,pc ;Restore register and return
|
|
238
|
|
239 *+
|
|
240 * FUNCTION PrinMsg
|
|
241 * PURPOSE Prints out the Error #xxx message
|
|
242 *-
|
|
243 PrinMsg equ *
|
|
244 pshs y,x,a ;Save registers
|
|
245 lda P$Path+2,y ;Get StdErr path number
|
|
246 leax Buf,u ;Get pointer to message
|
|
247 ldy #ErrLen ;Maximum ErrLen characters to print
|
|
248 os9 I$Write ;Write out error message
|
|
249 puls a,x,y,pc ;Restore registers and return
|
|
250
|
|
251 *+
|
|
252 * FUNCTION DoCR
|
|
253 * PURPOSE Prints a carriage return
|
|
254 *-
|
|
255 DoCR equ *
|
|
256 pshs x,d ;Save registers
|
|
257 ldb P$Task,y ;Get user task number
|
|
258 lda #$0D ;Load A with a CR
|
|
259 leax Buf,u ;Get pointer to buffer
|
|
260 os9 F$StABX ;Move the CR to the buffer
|
|
261 bsr PrinBuf ;Go print it
|
|
262 puls d,x,pc ;Restore registers and return
|
|
263
|
|
264 *+
|
|
265 * FUNCTION PrinBuf
|
|
266 * PURPOSE Prints out the string from user space
|
|
267 * TAKES X (in user space) = String to print
|
|
268 *-
|
|
269 PrinBuf equ *
|
|
270 pshs y,a ;Save registers
|
|
271 lda P$Path+2,y ;Get StdErr path number
|
|
272 ldy #BufLen ;Maximum BufLen characters to print
|
|
273 os9 I$WritLn ;Write out message
|
|
274 puls a,y,pc ;Restore registers and return
|
|
275
|
|
276 *+
|
|
277 * FUNCTION RdBuf
|
|
278 * PURPOSE Reads in a string from file to user space
|
|
279 * TAKES A = path number
|
|
280 * GIVES Buf (in user space) = String read in
|
|
281 *-
|
|
282 RdBuf equ *
|
|
283 pshs y,x ;Save registers
|
|
284 leax Buf,u ;Get pointer to buffer
|
|
285 ldy #BufLen ;Maximum BufLen characters to read
|
|
286 os9 I$ReadLn ;Read in line from file
|
|
287 puls x,y,pc ;Restore registers and return
|
|
288
|
|
289 *+
|
|
290 * FUNCTION OpenFil
|
|
291 * PURPOSE Open path to error message file
|
|
292 * TAKES Buf (in user space) = name of file
|
|
293 * GIVES A = Path number
|
|
294 *-
|
|
295 OpenFil equ *
|
|
296 pshs x ;Save register
|
|
297 lda #READ. ;Open path for read access
|
|
298 leax Buf,u ;Get pointer to string
|
|
299 os9 I$Open ;Open path
|
|
300 puls x,pc ;Restore registers and return A
|
|
301
|
|
302 *+
|
|
303 * FUNCTION ClosFil
|
|
304 * PURPOSE Close path to error message file
|
|
305 * TAKES A = Path number
|
|
306 *-
|
|
307 ClosFil equ *
|
|
308 os9 I$Close ;Close file
|
|
309 rts ;Return
|
|
310 P4Name fcc "OS9p4"
|
|
311 fcb $D
|
|
312 ErrMsg fcc "Error #000"
|
|
313 ErrLen equ *-ErrMsg
|
|
314 FilNam fcc "/dd/sys/errmsg"
|
|
315 fcb $D
|
|
316 FilLen equ *-FilNam
|
|
317
|
|
318 emod
|
|
319 eom equ *
|
|
320 end
|