Pristine Ack-5.5
[Ack-5.5.git] / mach / z80 / libmon / mon.s
1 .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:
22         pop ix  ! returnaddress
23
24         pop hl          ! monitor call number
25         ld a,l
26         cp 1
27         jp z,monexit    ! is it an exit?
28         cp 3
29         jp z,monread    ! is it a read?
30         cp 4
31         jp z,monwrite   ! is it a write?
32         cp 5
33         jp z,monopen    ! is it an open?
34         cp 6
35         jp z,monclose   ! is it a close?
36         cp 54
37         jp z,monioctl
38         jp ebadmon      ! trap
39
40 monexit:
41         jp 0x38
42
43 monread:
44         pop hl          ! file-descriptor, not used
45         pop hl          ! hl = pointer to output buffer
46         pop de          ! de = number of bytes to be read
47         ld bc,0         ! bc will contain the number of bytes actually read
48 1:      ld a,d
49         or e
50         jr z,2f
51         call getchar
52         push af
53         call putchar    ! echo character
54         pop af
55         ld (hl),a
56         inc hl
57         inc bc
58         dec de
59         cp 0x0A ! is it a newline?
60         jp nz,1b
61 2:      push bc
62         ld hl,0
63         push hl
64         jp (ix)
65
66 monwrite:
67         pop hl          ! file-descriptor, not used
68         pop hl          ! hl = pointer to output buffer
69         pop de          ! de = number of bytes
70         push de
71 1:      ld a,e
72         or d
73         jr z,2f
74         ld a,(hl)
75         call putchar
76         inc hl
77 dec de
78         jp 1b
79
80 2:      push de         ! no error
81         jp (ix)
82
83
84 monopen:
85         pop hl          ! pointer to string
86         pop hl          ! flag
87         ld hl,-1
88         push hl         ! push file descriptor
89         push hl         ! push error code twice
90         push hl
91         jp (ix)
92
93 monclose:
94         ex (sp),hl              ! pop file descriptor and push error code
95         pop hl          ! file descriptor
96         ld hl,-1
97         push hl         ! push error code twice
98         push hl
99         jp (ix)
100
101 monioctl:
102         pop hl          ! file descriptor
103         pop hl          ! request
104         ld hl,0
105         ex (sp),hl              ! remove argp and push error code
106         jp (ix)
107