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