-
Notifications
You must be signed in to change notification settings - Fork 2
/
devtty.c
207 lines (166 loc) · 3.59 KB
/
devtty.c
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
/**************************************************
UZI (Unix Z80 Implementation) Kernel: devtty.c
***************************************************/
#include "unix.h"
extern struct u_data udata;
#define TTYSIZ 132
char ttyinbuf[TTYSIZ];
struct s_queue ttyinq = {
ttyinbuf,
ttyinbuf,
ttyinbuf,
TTYSIZ,
0,
TTYSIZ/2
};
int stopflag; /* Flag for ^S/^Q */
int flshflag; /* Flag for ^O */
tty_read(minor, rawflag)
int16 minor;
int16 rawflag;
{
int nread;
nread = 0;
while (nread < udata.u_count)
{
for (;;)
{
di();
if (remq(&ttyinq,udata.u_base))
break;
psleep(&ttyinq);
if (udata.u_cursig || udata.u_ptab->p_pending) /* messy */
{
udata.u_error = EINTR;
return(-1);
}
}
ei();
if (nread++ == 0 && *udata.u_base == '\004') /* ^D */
return(0);
if (*udata.u_base == '\n')
break;
++udata.u_base;
}
return(nread);
}
tty_write(minor, rawflag)
int16 minor;
int16 rawflag;
{
int towrite;
towrite = udata.u_count;
while (udata.u_count-- != 0)
{
for (;;) /* Wait on the ^S/^Q flag */
{
di();
ifnot (stopflag)
break;
psleep(&stopflag);
if (udata.u_cursig || udata.u_ptab->p_pending) /* messy */
{
udata.u_error = EINTR;
return(-1);
}
}
ei();
ifnot (flshflag)
{
if (*udata.u_base == '\n')
_putc('\r');
_putc(*udata.u_base);
}
++udata.u_base;
}
return(towrite);
}
tty_open(minor)
int minor;
{
return(0);
}
tty_close(minor)
int minor;
{
return(0);
}
tty_ioctl(minor)
int minor;
{
return(-1);
}
/* This tty interrupt routine checks to see if the uart receiver actually
caused the interrupt. If so it adds the character to the tty input
queue, echoing and processing backspace and carriage return. If the queue
contains a full line, it wakes up anything waiting on it. If it is totally
full, it beeps at the user. */
tty_int()
{
register char c;
register found;
char oc;
found = 0;
again:
if( (in(0x72)&0x81) != 0x81 )
return (found);
c = in(0x73) & 0x7f;
if (c==0x1a) /* ^Z */
idump(); /* For debugging */
if (c == '\003') /* ^C */
sendsig(NULL, SIGINT);
else if (c == '\017') /* ^O */
flshflag = !flshflag;
else if (c == '\023') /* ^S */
stopflag = 1;
else if (c == '\021') /* ^Q */
{
stopflag = 0;
wakeup(&stopflag);
}
else if (c == '\b')
{
if (uninsq(&ttyinq,&oc))
{
if (oc == '\n')
insq(&ttyinq,oc); /* Don't erase past newline */
else
{
_putc('\b');
_putc(' ');
_putc('\b');
}
}
}
else
{
if (c == '\r' || c == '\n')
{
c = '\n';
_putc('\r');
}
if (insq(&ttyinq,c))
_putc(c);
else
_putc('\007'); /* Beep if no more room */
}
if (c == '\n' || c == '\004') /* ^D */
wakeup(&ttyinq);
found = 1;
goto again; /* Loop until the uart has no data ready */
}
#ifdef vax
_putc(c)
char c;
{
write(1,&c,1);
}
#else
_putc(c)
char c;
{
while(!(in(0x72)&02))
;
out(c,0x73);
}
#endif