Pristine Ack-5.5
[Ack-5.5.git] / mach / i80 / libmon / libmon_s.a
1 eÿmon.s\0\0\0\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0×\ 6.define .mon
2 .sect .text
3 .sect .rom
4 .sect .data
5 .sect .bss
6 .sect .text
7
8 ! Monitor call
9 ! Expects on stack:     monitor call number
10 !                       parameters
11 ! Implemented are the following monitor calls:
12 ! number  1:    exit
13 ! number  3:    read
14 ! number  4:    write
15 ! number  5:    open
16 ! number  6:    close
17 ! number 54:    ioctl
18 ! If called with a number of a call that is not implemented,
19 ! a trap is generated.
20
21 .mon:   pop h
22         shld .retadr
23         mov h,b
24         mov l,c
25         shld .bcreg
26
27         pop h           ! monitor call number
28         mov a,l
29         cpi 1
30         jz monexit      ! is it an exit?
31         cpi 3
32         jz monread      ! is it a read?
33         cpi 4
34         jz monwrite     ! is it a write?
35         cpi 5
36         jz monopen      ! is it an open?
37         cpi 6
38         jz monclose     ! is it a close?
39         cpi 54
40         jz monioctl
41         jmp ebadmon     ! trap
42
43 monexit:
44         jmp .stop
45
46 monread:
47         pop h           ! file-descriptor, not used
48         pop h           ! hl = pointer to output buffer
49         pop d           ! de = number of bytes to be read
50         lxi b,0         ! bc will contain the number of bytes actually read
51 1:      mov a,d
52         ora e
53         jz 2f
54         call getchar
55         push psw
56         call putchar    ! echo character
57         pop psw
58         mov m,a
59         inx h
60         inx b
61         dcx d
62         cpi 0x0A        ! is it a newline?
63         jnz 1b
64 2:      push b
65         lxi h,0
66         push h
67         jmp monret
68
69 monwrite:
70         pop h           ! file-descriptor, not used
71         pop h           ! hl = pointer to output buffer
72         pop d           ! de = number of bytes
73         push d
74 1:      mov a,e
75         ora d
76         jz 2f
77         mov a,m
78         call putchar
79         inx h
80         dcx d
81         jmp 1b
82
83 2:      push d          ! no error
84         jmp monret
85
86
87 monopen:
88         pop h           ! pointer to string
89         pop h           ! flag
90         lxi h,-1
91         push h          ! push file descriptor
92         push h          ! push error code twice
93         push h
94         jmp monret
95
96 monclose:
97         lxi h,0
98         xthl            ! remove file descriptor and push error code
99         jmp monret
100
101 monioctl:
102         pop h           ! file descriptor
103         pop h           ! request
104         lxi h,0
105         xthl            ! remove argp and push error code
106         jmp monret
107
108 monret:
109         lhld .bcreg
110         mov b,h
111         mov c,l
112         lhld .retadr
113         pchl
114 \0trp.s\0\0\0\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0ô\v.define .trp
115 .define earray, erange, eset, eiovfl, efovfl, efunfl, eidivz, eidivz
116 .define efdivz, eiund, efund, econv, estack, eheap, eillins, eoddz
117 .define ecase, ememflt, ebadptr, ebadpc, ebadlae, ebadmon, ebadlin, ebadgto
118 .define eunimpl
119 .sect .text
120 .sect .rom
121 .sect .data
122 .sect .bss
123 .sect .text
124
125 ! Trap routine
126 ! Expects trap number on stack.
127 ! Just returns if trap has to be ignored.
128 ! Otherwise it calls a user-defined trap handler if provided.
129 ! When no user-defined trap handler is provided or when the user-defined
130 ! trap handler causes a new trap, a message is printed
131 ! and control is returned to the monitor.
132
133         EARRAY  =  0
134         ERANGE  =  1
135         ESET    =  2
136         EIOVFL  =  3
137         EFOVFL  =  4
138         EFUNFL  =  5
139         EIDIVZ  =  6
140         EFDIVZ  =  7
141         EIUND   =  8
142         EFUND   =  9
143         ECONV   = 10
144         ESTACK  = 16
145         EHEAP   = 17
146         EILLINS = 18
147         EODDZ   = 19
148         ECASE   = 20
149         EMEMFLT = 21
150         EBADPTR = 22
151         EBADPC  = 23
152         EBADLAE = 24
153         EBADMON = 25
154         EBADLIN = 26
155         EBADGTO = 27
156         EUNIMPL = 63            ! unimplemented em-instruction called
157
158 earray: lxi h,EARRAY
159         push h
160         call .trp
161         ret
162
163 erange: lxi h,ERANGE
164         push h
165         call .trp
166         ret
167
168 eset:   lxi h,ESET
169         push h
170         call .trp
171         ret
172
173 eiovfl: lxi h,EIOVFL
174         push h
175         call .trp
176         ret
177
178 efovfl: lxi h,EFOVFL
179         push h
180         call .trp
181         ret
182
183 efunfl: lxi h,EFUNFL
184         push h
185         call .trp
186         ret
187
188 eidivz: lxi h,EIDIVZ
189         push h
190         call .trp
191         ret
192
193 efdivz: lxi h,EFDIVZ
194         push h
195         call .trp
196         ret
197
198 eiund:  lxi h,EIUND
199         push h
200         call .trp
201         ret
202
203 efund:  lxi h,EFUND
204         push h
205         call .trp
206         ret
207
208 econv:  lxi h,ECONV
209         push h
210         call .trp
211         ret
212
213 estack: lxi h,ESTACK
214         push h
215         call .trp
216         ret
217
218 eheap:  lxi h,EHEAP
219         push h
220         call .trp
221         ret
222
223 eillins:lxi h,EILLINS
224         push h
225         call .trp
226         ret
227
228 eoddz:  lxi h,EODDZ
229         push h
230         call .trp
231         ret
232
233 ecase:  lxi h,ECASE
234         push h
235         call .trp
236         ret
237
238 ememflt:lxi h,EMEMFLT
239         push h
240         call .trp
241         ret
242
243 ebadptr:lxi h,EBADPTR
244         push h
245         call .trp
246         ret
247
248 ebadpc: lxi h,EBADPC
249         push h
250         call .trp
251         ret
252
253 ebadlae:lxi h,EBADLAE
254         push h
255         call .trp
256         ret
257
258 ebadmon:lxi h,EBADMON
259         push h
260         call .trp
261         ret
262
263 ebadlin:lxi h,EBADLIN
264         push h
265         call .trp
266         ret
267
268 ebadgto:lxi h,EBADGTO
269         push h
270         call .trp
271         ret
272
273 eunimpl:lxi h,EUNIMPL
274         push h
275         call .trp
276         ret
277
278 .trp:
279         pop h
280         xthl
281         push h                  ! trap number and return address exchanged
282         mov a,l
283         cpi 16
284         jnc 3f                  ! jump if trap cannot be ignored
285
286 ! check if trap has to be ignored
287         xchg                    ! de = trap number
288         lhld .ignmask
289         push h                  ! hl = set to be tested
290         push d
291         call .inn2              ! de = 1 if bit is set, 0 otherwise
292         mov a,e
293         rar
294         jnc 3f                  ! jump if trap should not be ignored
295         pop h                   ! remove trap number
296         ret                     ! OGEN DICHT EN ... SPRING!!!
297
298 3:
299         lhld .trapproc          ! user defined trap handler?
300         mov a,l
301         ora h
302         jz 1f                   ! jump if there was not
303         xra a
304         sta .trapproc           ! .trapproc := 0
305         sta .trapproc+1
306         lxi d,2f                
307         push d
308         pchl                    ! call user defined trap handler
309 2:
310         pop d
311         ret
312 1:
313         mvi a,0x0A              !newline
314         call putchar
315         lxi d,text1
316         call prstring
317         pop h
318         call prdec
319         lxi d,text2
320         call prstring
321         lhld hol0
322         call prdec
323         lxi d,text3
324         call prstring
325         lhld hol0+4
326         xchg
327         call prstring
328         mvi a,0x0A              !newline
329         call putchar
330         jmp .stop
331
332
333 text1:  .asciz "trap number "
334 text2:  .asciz "\nline "
335 text3:  .asciz " of file "
336
337 inn2.s\0\0\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0Z\ 2.define .inn2
338 .sect .text
339 .sect .rom
340 .sect .data
341 .sect .bss
342 .sect .text
343
344 ! Bit test on 16 bits set
345 ! Expects on stack:     bit number
346 !                       set to be tested
347 ! Yields in de-registers:       0 if bit is reset or bit number out of range
348 !                               1 if bit is set
349
350 .inn2:  pop h
351         shld .retadr
352
353         pop d           !bit number
354         pop h           !set to be tested
355         mov a,e
356         cpi 16
357         jnc 3f
358         cpi 8
359         jnc 1f
360         mov e,a
361         mov a,l         !l-reg contains the wanted bit
362         jmp 2f
363
364 1:      sbi 8
365         mov e,a
366         mov a,h         !h-reg contains the wanted bit
367
368 2:      dcr e
369         jm 4f
370         rar
371         jmp 2b
372
373 3:      xra a           !return 0 if bit number out of range
374 4:      ani 1
375         mov e,a
376         mvi d,0
377
378         lhld .retadr
379         pchl
380 prstring.s\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0D\ 1.define prstring
381 .sect .text
382 .sect .rom
383 .sect .data
384 .sect .bss
385 .sect .text
386
387 ! print a string of characters to the console
388 ! entry: de-reg points to the string
389 !        string terminator is 0x00
390 ! exit:  de-reg points to string terminator
391
392 prstring:
393         push psw
394 1:      ldax d
395         ora a
396         jz 2f
397         call putchar
398         inx d
399         jmp 1b
400 2:      pop psw
401         ret
402
403 prdec.s\0.s\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0U\ 2.define prdec
404 .sect .text
405 .sect .rom
406 .sect .data
407 .sect .bss
408 .sect .text
409
410 ! print hl-reg as a decimal number.
411
412 prdec:  push h
413         push d
414         push b
415         push psw
416         lxi d,table
417         mvi b,4
418 1:      call convert
419         ori 0x30
420         call putchar
421         dcr b
422         jnz 1b
423         mov a,l
424         ori 0x30
425         call putchar
426         pop psw
427         pop b
428         pop d
429         pop h
430         ret
431
432 convert:
433         push b
434         mov b,h
435         mov c,l
436         xchg
437         mov e,m
438         inx h
439         mov d,m
440         inx h
441         push h          ! save pointer to new value
442         mov h,b
443         mov l,c
444         mvi b,255
445 1:      inr b
446         mov a,l
447         sub e
448         mov l,a
449         mov a,h
450         sbb d
451         mov h,a
452         jnc 1b
453         dad d
454         mov a,b
455         pop d
456         pop b
457         ret
458
459 table:
460         .data2  10000
461         .data2  1000
462         .data2  100
463         .data2  10
464
465 pchar.her.s\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0Ý\ 1.define getchar, putchar
466 .sect .text
467 .sect .rom
468 .sect .data
469 .sect .bss
470 .sect .text
471
472 ! These getchar and putchar routines can be used for HERMAC computer
473
474 ! Read a character from HERMAC-monitor
475 ! Character is returned in a-reg
476
477 getchar:
478         in 0xF1
479         ani 1
480         jz getchar
481         in 0xF0
482         cpi 0x0D
483         jnz 1f
484         mvi a,0x0A
485 1:      ret
486
487 ! Write character on HERMAC monitor
488 ! Assumes character in a-reg
489
490 putchar:
491         cpi 0x0A
492         jnz 1f
493         mvi a,0x1F
494 1:      push psw
495 2:      in 0xF1
496         ani 4
497         jz 2b
498         pop psw
499         out 0xF0
500         ret
501