First Commit of my working state
[simh.git] / NOVA / nova_tt1.c
1 /* nova_tt1.c: NOVA second terminal simulator
2
3 Copyright (c) 1993-2008, Robert M. Supnik
4 Written by Bruce Ray and used with his gracious permission.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 ROBERT M SUPNIK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23 Except as contained in this notice, the name of Robert M Supnik shall not be
24 used in advertising or otherwise to promote the sale, use or other dealings
25 in this Software without prior written authorization from Robert M Supnik.
26
27 tti1 second terminal input
28 tto1 second terminal output
29
30 09-May-03 RMS Added network device flag
31 05-Jan-03 RMS Fixed calling sequence for setmod
32 03-Oct-02 RMS Added DIBs
33 22-Aug-02 RMS Updated for changes in sim_tmxr
34 30-May-02 RMS Widened POS to 32b
35 06-Jan-02 RMS Revised enable/disable support
36 30-Dec-01 RMS Added show statistics, set disconnect
37 30-Nov-01 RMS Added extended SET/SHOW support
38 17-Sep-01 RMS Changed to use terminal multiplexor library
39 07-Sep-01 RMS Moved function prototypes
40 31-May-01 RMS Added multiconsole support
41 26-Apr-01 RMS Added device enable/disable support
42 */
43
44 #include "nova_defs.h"
45 #include "sim_sock.h"
46 #include "sim_tmxr.h"
47
48 #define UNIT_V_DASHER (UNIT_V_UF + 0) /* Dasher mode */
49 #define UNIT_DASHER (1 << UNIT_V_DASHER)
50
51 extern int32 int_req, dev_busy, dev_done, dev_disable;
52 extern int32 tmxr_poll; /* calibrated poll */
53 TMLN tt1_ldsc = { 0 }; /* line descriptors */
54 TMXR tt_desc = { 1, 0, 0, &tt1_ldsc }; /* mux descriptor */
55
56 DEVICE tti1_dev, tto1_dev;
57 int32 tti1 (int32 pulse, int32 code, int32 AC);
58 int32 tto1 (int32 pulse, int32 code, int32 AC);
59 t_stat tti1_svc (UNIT *uptr);
60 t_stat tto1_svc (UNIT *uptr);
61 t_stat tti1_reset (DEVICE *dptr);
62 t_stat tto1_reset (DEVICE *dptr);
63 t_stat ttx1_setmod (UNIT *uptr, int32 val, char *cptr, void *desc);
64 t_stat tti1_attach (UNIT *uptr, char *cptr);
65 t_stat tti1_detach (UNIT *uptr);
66 t_stat tti1_summ (FILE *st, UNIT *uptr, int32 val, void *desc);
67 t_stat tti1_show (FILE *st, UNIT *uptr, int32 val, void *desc);
68 void ttx1_enbdis (int32 dis);
69
70 /* TTI1 data structures
71
72 tti1_dev TTI1 device descriptor
73 tti1_unit TTI1 unit descriptor
74 tti1_reg TTI1 register list
75 ttx1_mod TTI1/TTO1 modifiers list
76 */
77
78 DIB tti1_dib = { DEV_TTI1, INT_TTI1, PI_TTI1, &tti1 };
79
80 UNIT tti1_unit = { UDATA (&tti1_svc, UNIT_ATTABLE, 0), KBD_POLL_WAIT };
81
82 REG tti1_reg[] = {
83 { ORDATA (BUF, tti1_unit.buf, 8) },
84 { FLDATA (BUSY, dev_busy, INT_V_TTI1) },
85 { FLDATA (DONE, dev_done, INT_V_TTI1) },
86 { FLDATA (DISABLE, dev_disable, INT_V_TTI1) },
87 { FLDATA (INT, int_req, INT_V_TTI1) },
88 { DRDATA (POS, tt1_ldsc.rxcnt, 32), PV_LEFT },
89 { DRDATA (TIME, tti1_unit.wait, 24), REG_NZ + PV_LEFT },
90 { NULL }
91 };
92
93 MTAB tti1_mod[] = {
94 { UNIT_DASHER, 0, "ANSI", "ANSI", &ttx1_setmod },
95 { UNIT_DASHER, UNIT_DASHER, "Dasher", "DASHER", &ttx1_setmod },
96 { UNIT_ATT, UNIT_ATT, "summary", NULL, NULL, &tti1_summ },
97 { MTAB_XTD | MTAB_VDV, 0, NULL, "DISCONNECT",
98 &tmxr_dscln, NULL, &tt_desc },
99 { MTAB_XTD | MTAB_VDV | MTAB_NMO, 1, "CONNECTIONS", NULL,
100 NULL, &tti1_show, NULL },
101 { MTAB_XTD | MTAB_VDV | MTAB_NMO, 0, "STATISTICS", NULL,
102 NULL, &tti1_show, NULL },
103 { 0 }
104 };
105
106 DEVICE tti1_dev = {
107 "TTI1", &tti1_unit, tti1_reg, tti1_mod,
108 1, 10, 31, 1, 8, 8,
109 &tmxr_ex, &tmxr_dep, &tti1_reset,
110 NULL, &tti1_attach, &tti1_detach,
111 &tti1_dib, DEV_NET | DEV_DISABLE
112 };
113
114 /* TTO1 data structures
115
116 tto1_dev TTO1 device descriptor
117 tto1_unit TTO1 unit descriptor
118 tto1_reg TTO1 register list
119 */
120
121 DIB tto1_dib = { DEV_TTO1, INT_TTO1, PI_TTO1, &tto1 };
122
123 UNIT tto1_unit = { UDATA (&tto1_svc, 0, 0), SERIAL_OUT_WAIT };
124
125 REG tto1_reg[] = {
126 { ORDATA (BUF, tto1_unit.buf, 8) },
127 { FLDATA (BUSY, dev_busy, INT_V_TTO1) },
128 { FLDATA (DONE, dev_done, INT_V_TTO1) },
129 { FLDATA (DISABLE, dev_disable, INT_V_TTO1) },
130 { FLDATA (INT, int_req, INT_V_TTO1) },
131 { DRDATA (POS, tt1_ldsc.txcnt, 32), PV_LEFT },
132 { DRDATA (TIME, tto1_unit.wait, 24), PV_LEFT },
133 { NULL }
134 };
135
136 MTAB tto1_mod[] = {
137 { UNIT_DASHER, 0, "ANSI", "ANSI", &ttx1_setmod },
138 { UNIT_DASHER, UNIT_DASHER, "Dasher", "DASHER", &ttx1_setmod },
139 { 0 }
140 };
141
142 DEVICE tto1_dev = {
143 "TTO1", &tto1_unit, tto1_reg, tto1_mod,
144 1, 10, 31, 1, 8, 8,
145 NULL, NULL, &tto1_reset,
146 NULL, NULL, NULL,
147 &tto1_dib, DEV_DISABLE
148 };
149
150 /* Terminal input: IOT routine */
151
152 int32 tti1 (int32 pulse, int32 code, int32 AC)
153 {
154 int32 iodata;
155
156 iodata = (code == ioDIA)? tti1_unit.buf & 0377: 0;
157 switch (pulse) { /* decode IR<8:9> */
158
159 case iopS: /* start */
160 dev_busy = dev_busy | INT_TTI1; /* set busy */
161 dev_done = dev_done & ~INT_TTI1; /* clear done, int */
162 int_req = int_req & ~INT_TTI1;
163 break;
164
165 case iopC: /* clear */
166 dev_busy = dev_busy & ~INT_TTI1; /* clear busy */
167 dev_done = dev_done & ~INT_TTI1; /* clear done, int */
168 int_req = int_req & ~INT_TTI1;
169 break;
170 } /* end switch */
171
172 return iodata;
173 }
174
175 /* Unit service */
176
177 t_stat tti1_svc (UNIT *uptr)
178 {
179 int32 temp, newln;
180
181 if (tt1_ldsc.conn) { /* connected? */
182 tmxr_poll_rx (&tt_desc); /* poll for input */
183 if (temp = tmxr_getc_ln (&tt1_ldsc)) { /* get char */
184 uptr->buf = temp & 0177;
185 if ((uptr->flags & UNIT_DASHER) &&
186 (uptr->buf == '\r'))
187 uptr->buf = '\n'; /* Dasher: cr->nl */
188 dev_busy = dev_busy & ~INT_TTI1; /* clear busy */
189 dev_done = dev_done | INT_TTI1; /* set done */
190 int_req = (int_req & ~INT_DEV) | (dev_done & ~dev_disable);
191 }
192 sim_activate (uptr, uptr->wait); /* continue poll */
193 }
194 if (uptr->flags & UNIT_ATT) { /* attached? */
195 newln = tmxr_poll_conn (&tt_desc); /* poll connect */
196 if (newln >= 0) { /* got one? */
197 sim_activate (&tti1_unit, tti1_unit.wait);
198 tt1_ldsc.rcve = 1; /* rcv enabled */
199 }
200 sim_activate (uptr, tmxr_poll); /* sched poll */
201 }
202 return SCPE_OK;
203 }
204
205 /* Reset routine */
206
207 t_stat tti1_reset (DEVICE *dptr)
208 {
209 ttx1_enbdis (dptr->flags & DEV_DIS); /* sync devices */
210 tti1_unit.buf = 0; /* <not DG compatible> */
211 dev_busy = dev_busy & ~INT_TTI1; /* clear busy */
212 dev_done = dev_done & ~INT_TTI1; /* clear done, int */
213 int_req = int_req & ~INT_TTI1;
214 if (tt1_ldsc.conn) { /* if conn, */
215 sim_activate (&tti1_unit, tti1_unit.wait); /* activate, */
216 tt1_ldsc.rcve = 1; /* enable */
217 }
218 else if (tti1_unit.flags & UNIT_ATT) /* if attached, */
219 sim_activate (&tti1_unit, tmxr_poll); /* activate */
220 else sim_cancel (&tti1_unit); /* else stop */
221 return SCPE_OK;
222 }
223
224 /* Terminal output: IOT routine */
225
226 int32 tto1 (int32 pulse, int32 code, int32 AC)
227 {
228 if (code == ioDOA) tto1_unit.buf = AC & 0377;
229 switch (pulse) { /* decode IR<8:9> */
230
231 case iopS: /* start */
232 dev_busy = dev_busy | INT_TTO1; /* set busy */
233 dev_done = dev_done & ~INT_TTO1; /* clear done, int */
234 int_req = int_req & ~INT_TTO1;
235 sim_activate (&tto1_unit, tto1_unit.wait); /* activate unit */
236 break;
237
238 case iopC: /* clear */
239 dev_busy = dev_busy & ~INT_TTO1; /* clear busy */
240 dev_done = dev_done & ~INT_TTO1; /* clear done, int */
241 int_req = int_req & ~INT_TTO1;
242 sim_cancel (&tto1_unit); /* deactivate unit */
243 break;
244 } /* end switch */
245
246 return 0;
247 }
248
249 /* Unit service */
250
251 t_stat tto1_svc (UNIT *uptr)
252 {
253 int32 c;
254
255 dev_busy = dev_busy & ~INT_TTO1; /* clear busy */
256 dev_done = dev_done | INT_TTO1; /* set done */
257 int_req = (int_req & ~INT_DEV) | (dev_done & ~dev_disable);
258 c = tto1_unit.buf & 0177;
259 if ((tto1_unit.flags & UNIT_DASHER) && (c == 031)) c = '\b';
260 if (tt1_ldsc.conn) { /* connected? */
261 if (tt1_ldsc.xmte) { /* tx enabled? */
262 tmxr_putc_ln (&tt1_ldsc, c); /* output char */
263 tmxr_poll_tx (&tt_desc); /* poll xmt */
264 }
265 else {
266 tmxr_poll_tx (&tt_desc); /* poll xmt */
267 sim_activate (&tto1_unit, tmxr_poll); /* wait */
268 }
269 }
270 return SCPE_OK;
271 }
272
273 /* Reset routine */
274
275 t_stat tto1_reset (DEVICE *dptr)
276 {
277 ttx1_enbdis (dptr->flags & DEV_DIS); /* sync devices */
278 tto1_unit.buf = 0; /* <not DG compatible> */
279 dev_busy = dev_busy & ~INT_TTO1; /* clear busy */
280 dev_done = dev_done & ~INT_TTO1; /* clear done, int */
281 int_req = int_req & ~INT_TTO1;
282 sim_cancel (&tto1_unit); /* deactivate unit */
283 return SCPE_OK;
284 }
285
286 t_stat ttx1_setmod (UNIT *uptr, int32 val, char *cptr, void *desc)
287 {
288 tti1_unit.flags = (tti1_unit.flags & ~UNIT_DASHER) | val;
289 tto1_unit.flags = (tto1_unit.flags & ~UNIT_DASHER) | val;
290 return SCPE_OK;
291 }
292
293 /* Attach routine */
294
295 t_stat tti1_attach (UNIT *uptr, char *cptr)
296 {
297 t_stat r;
298
299 r = tmxr_attach (&tt_desc, uptr, cptr); /* attach */
300 if (r != SCPE_OK) return r; /* error */
301 sim_activate (uptr, tmxr_poll); /* start poll */
302 return SCPE_OK;
303 }
304
305 /* Detach routine */
306
307 t_stat tti1_detach (UNIT *uptr)
308 {
309 t_stat r;
310
311 r = tmxr_detach (&tt_desc, uptr); /* detach */
312 tt1_ldsc.rcve = 0; /* disable rcv */
313 sim_cancel (uptr); /* stop poll */
314 return r;
315 }
316
317 /* Show summary processor */
318
319 t_stat tti1_summ (FILE *st, UNIT *uptr, int32 val, void *desc)
320 {
321 if (tt1_ldsc.conn) fprintf (st, "connected");
322 else fprintf (st, "disconnected");
323 return SCPE_OK;
324 }
325
326 /* SHOW CONN/STAT processor */
327
328 t_stat tti1_show (FILE *st, UNIT *uptr, int32 val, void *desc)
329 {
330 if (val) tmxr_fconns (st, &tt1_ldsc, -1);
331 else tmxr_fstats (st, &tt1_ldsc, -1);
332 return SCPE_OK;
333 }
334
335 /* Enable/disable device */
336
337 void ttx1_enbdis (int32 dis)
338 {
339 if (dis) {
340 tti1_dev.flags = tto1_dev.flags | DEV_DIS;
341 tto1_dev.flags = tto1_dev.flags | DEV_DIS;
342 }
343 else {
344 tti1_dev.flags = tti1_dev.flags & ~DEV_DIS;
345 tto1_dev.flags = tto1_dev.flags & ~DEV_DIS;
346 }
347 return;
348 }