-
Notifications
You must be signed in to change notification settings - Fork 0
/
wdosterm.asm
233 lines (205 loc) · 4 KB
/
wdosterm.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
;
; Z80 WeirDOS 0.4
;
; wdosterm.asm
;
; Routines for terminal (console) I/O
;
;
; A Disk Operating System for Z80 microcomputers, implementing
; the CP/M 2.2 API and FAT12/FAT16 filesystems.
;
; Coptright (C) 2021 Alexis Kotlowy
;
; This file is part of WeirDOS (aka WDOS)
;
; WeirDOS is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; WeirDOS is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with WeirDOS. If not, see <https://www.gnu.org/licenses/>.
;
crlf: mvi c, CR
call conout
mvi c, LF
jmp conout
; Stub for conin
conina: call conin ; Get character as requrested
sta rval ; Set return value
ret
; Stub for reader
readera call reader ; Get character as requrested
sta rval ; Set return value
ret
;
; Function 02h (2)
;
; Console output
cout: call const
jrz .1
.wait call conin
cpi CTRLS ; XOFF
jrz .wait
cpi CTRLC ; ^C
jz exit ; Terminate program
.1: lded param
mov c, e
jmp conout
;
; Function 06h (6)
;
; Directo console I/O
; E = 0FFh
dcons: mov a, e ; For compare
cpi 0FFh
jnz cout
; Else we input a character
call const
ora a
rz ; Return if no character available
call conin ; Else get it and return
sta rval
ret
;
; Function 09h (9)
;
; Print. Terminates on '$' in string.
; Changes A, DE.
; A returns with '$'. DE returns pointing
; at the end of the string.
print: ldax d
inx d
cpi '$'
rz
push d
mov c, a
call conout
pop d
jr print
; Function 0Ah (10)
;
; Buffered Console Input
; Enter with DE as buffer location
iredo: mvi c, '\' ; Start a new line
call conout
call crlf
input: lhld param ; Parameters location
mov a, l
ora h
jnz inp1
lhld dmaadr ; DE=0, use DMA address
shld param
inp1: mov b, m ; Buffer size in B
inx h ; Buffer length
inx h ; Point at bytes to store
mvi c, 0 ; Buffer count in C
inpl: push h
push b
call conin
pop b
pop h
mov d, a ; Keep received character in D
cpi ' ' ; Control character?
jc ictrl
istore: mov a, c ; Compare B to C
cmp b
jnc inpl ; Jump if B >= C, discard character
mov m, d ; Store character
inr c ; Increment character count
inx h ; Next memory location
push h
push b
mov c, d ; Print character in C
mov a, d ; Don't re-echo control characters
cpi ' '
cnc conout
pop b
pop h
jmp inpl ; Continue
ictrl: cpi RUBOUT
jz inpbs
cpi BS
jz inpbs
cpi CR
jz inpcr
cpi ESCAP ; Redo?
jz iredo
; Else, print caret and character
push b ; Count in C
push d ; Character in D
mvi c, '^' ; Print a caret
call conout
pop d ; Restore character
push d
mov a, d ; Make it visible
adi '@'
mov c, a ; Print it
call conout
pop d
pop b
mov a, d
cpi CTRLC ; Reboot on ctrl-C
jz reload
jmp istore ; Store D
inpbs: mov a, c ; Do nothing if at character 0
ora a
jz inpl
dcr c ; Decrement character count
dcx h ; Decrement character pointer
mov a, m
cpi TAB ; Erase a tab (7 characters plus control)
cz inptab
cpi ' ' ; Erase two characters if it's a control
cc inpclr
call inpclr ; Erase normal character
jmp inpl
inptab: push psw
mvi b, 7
inptl: call inpclr
djnz inptl
pop psw
ret
; Clear the previous character
inpclr: push h
push b
mvi c, 8 ; Rubout character
call conout
mvi c, ' '
call conout
mvi c, 8
call conout
pop b
pop h
ret
inpcr: lhld param ; Get parameters location
inx h ; Point at length
mov m, c ; Store character count
mvi c, CR ; emit CR on exit
jmp conout
;
; Function 0Bh (11)
;
; Console status
;
cstat: call const ; A=status
sta rval ; A=L=status
ret
; Function 07h (7)
;
; Return I/O Byte
giobyt: lda IOBYTE
sta rval
ret
; Function 08h (8)
;
; Set I/O byte from E
siobyt: mov a, e
sta IOBYTE
ret