1 /* nova_tt1.c: NOVA second terminal simulator
3 Copyright (c) 1993-2008, Robert M. Supnik
4 Written by Bruce Ray and used with his gracious permission.
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:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
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.
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.
27 tti1 second terminal input
28 tto1 second terminal output
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
44 #include "nova_defs.h"
48 #define UNIT_V_DASHER (UNIT_V_UF + 0) /* Dasher mode */
49 #define UNIT_DASHER (1 << UNIT_V_DASHER)
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 */
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
);
70 /* TTI1 data structures
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
78 DIB tti1_dib
= { DEV_TTI1
, INT_TTI1
, PI_TTI1
, &tti1
};
80 UNIT tti1_unit
= { UDATA (&tti1_svc
, UNIT_ATTABLE
, 0), KBD_POLL_WAIT
};
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
},
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
},
107 "TTI1", &tti1_unit
, tti1_reg
, tti1_mod
,
109 &tmxr_ex
, &tmxr_dep
, &tti1_reset
,
110 NULL
, &tti1_attach
, &tti1_detach
,
111 &tti1_dib
, DEV_NET
| DEV_DISABLE
114 /* TTO1 data structures
116 tto1_dev TTO1 device descriptor
117 tto1_unit TTO1 unit descriptor
118 tto1_reg TTO1 register list
121 DIB tto1_dib
= { DEV_TTO1
, INT_TTO1
, PI_TTO1
, &tto1
};
123 UNIT tto1_unit
= { UDATA (&tto1_svc
, 0, 0), SERIAL_OUT_WAIT
};
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
},
137 { UNIT_DASHER
, 0, "ANSI", "ANSI", &ttx1_setmod
},
138 { UNIT_DASHER
, UNIT_DASHER
, "Dasher", "DASHER", &ttx1_setmod
},
143 "TTO1", &tto1_unit
, tto1_reg
, tto1_mod
,
145 NULL
, NULL
, &tto1_reset
,
147 &tto1_dib
, DEV_DISABLE
150 /* Terminal input: IOT routine */
152 int32
tti1 (int32 pulse
, int32 code
, int32 AC
)
156 iodata
= (code
== ioDIA
)? tti1_unit
.buf
& 0377: 0;
157 switch (pulse
) { /* decode IR<8:9> */
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
;
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
;
177 t_stat
tti1_svc (UNIT
*uptr
)
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
) &&
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
);
192 sim_activate (uptr
, uptr
->wait
); /* continue poll */
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 */
200 sim_activate (uptr
, tmxr_poll
); /* sched poll */
207 t_stat
tti1_reset (DEVICE
*dptr
)
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 */
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 */
224 /* Terminal output: IOT routine */
226 int32
tto1 (int32 pulse
, int32 code
, int32 AC
)
228 if (code
== ioDOA
) tto1_unit
.buf
= AC
& 0377;
229 switch (pulse
) { /* decode IR<8:9> */
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 */
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 */
251 t_stat
tto1_svc (UNIT
*uptr
)
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 */
266 tmxr_poll_tx (&tt_desc
); /* poll xmt */
267 sim_activate (&tto1_unit
, tmxr_poll
); /* wait */
275 t_stat
tto1_reset (DEVICE
*dptr
)
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 */
286 t_stat
ttx1_setmod (UNIT
*uptr
, int32 val
, char *cptr
, void *desc
)
288 tti1_unit
.flags
= (tti1_unit
.flags
& ~UNIT_DASHER
) | val
;
289 tto1_unit
.flags
= (tto1_unit
.flags
& ~UNIT_DASHER
) | val
;
295 t_stat
tti1_attach (UNIT
*uptr
, char *cptr
)
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 */
307 t_stat
tti1_detach (UNIT
*uptr
)
311 r
= tmxr_detach (&tt_desc
, uptr
); /* detach */
312 tt1_ldsc
.rcve
= 0; /* disable rcv */
313 sim_cancel (uptr
); /* stop poll */
317 /* Show summary processor */
319 t_stat
tti1_summ (FILE *st
, UNIT
*uptr
, int32 val
, void *desc
)
321 if (tt1_ldsc
.conn
) fprintf (st
, "connected");
322 else fprintf (st
, "disconnected");
326 /* SHOW CONN/STAT processor */
328 t_stat
tti1_show (FILE *st
, UNIT
*uptr
, int32 val
, void *desc
)
330 if (val
) tmxr_fconns (st
, &tt1_ldsc
, -1);
331 else tmxr_fstats (st
, &tt1_ldsc
, -1);
335 /* Enable/disable device */
337 void ttx1_enbdis (int32 dis
)
340 tti1_dev
.flags
= tto1_dev
.flags
| DEV_DIS
;
341 tto1_dev
.flags
= tto1_dev
.flags
| DEV_DIS
;
344 tti1_dev
.flags
= tti1_dev
.flags
& ~DEV_DIS
;
345 tto1_dev
.flags
= tto1_dev
.flags
& ~DEV_DIS
;