1 /* pdp8_ttx.c: PDP-8 additional terminals simulator
3 Copyright (c) 1993-2007, Robert M Supnik
5 Permission is hereby granted, free of charge, to any person obtaining a
6 copy of this software and associated documentation files (the "Software"),
7 to deal in the Software without restriction, including without limitation
8 the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 and/or sell copies of the Software, and to permit persons to whom the
10 Software is furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 ROBERT M SUPNIK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of Robert M Supnik shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from Robert M Supnik.
26 ttix,ttox PT08/KL8JA terminal input/output
28 07-Jun-06 RMS Added UNIT_IDLE flag
29 06-Jul-06 RMS Fixed bug in DETACH routine
30 22-Nov-05 RMS Revised for new terminal processing routines
31 29-Jun-05 RMS Added SET TTOXn DISCONNECT
32 Fixed bug in SET LOG/NOLOG
33 21-Jun-05 RMS Fixed bug in SHOW CONN/STATS
34 05-Jan-04 RMS Revised for tmxr library changes
35 09-May-03 RMS Added network device flag
36 25-Apr-03 RMS Revised for extended file support
37 22-Dec-02 RMS Added break support
38 02-Nov-02 RMS Added 7B/8B support
39 04-Oct-02 RMS Added DIB, device number support
40 22-Aug-02 RMS Updated for changes to sim_tmxr.c
41 06-Jan-02 RMS Added device enable/disable support
42 30-Dec-01 RMS Complete rebuild
43 30-Nov-01 RMS Added extended SET/SHOW support
45 This module implements four individual serial interfaces similar in function
46 to the console. These interfaces are mapped to Telnet based connections as
47 though they were the four lines of a terminal multiplexor. The connection
48 polling mechanism is superimposed onto the keyboard of the first interface.
51 #include "pdp8_defs.h"
57 #define TTX_MASK (TTX_LINES - 1)
59 #define TTX_GETLN(x) (((x) >> 4) & TTX_MASK)
61 extern int32 int_req
, int_enable
, dev_done
, stop_inst
;
63 uint8 ttix_buf
[TTX_LINES
] = { 0 }; /* input buffers */
64 uint8 ttox_buf
[TTX_LINES
] = { 0 }; /* output buffers */
65 int32 ttx_tps
= 100; /* polls per second */
66 TMLN ttx_ldsc
[TTX_LINES
] = { 0 }; /* line descriptors */
67 TMXR ttx_desc
= { TTX_LINES
, 0, 0, ttx_ldsc
}; /* mux descriptor */
69 DEVICE ttix_dev
, ttox_dev
;
70 int32
ttix (int32 IR
, int32 AC
);
71 int32
ttox (int32 IR
, int32 AC
);
72 t_stat
ttix_svc (UNIT
*uptr
);
73 t_stat
ttix_reset (DEVICE
*dptr
);
74 t_stat
ttox_svc (UNIT
*uptr
);
75 t_stat
ttox_reset (DEVICE
*dptr
);
76 t_stat
ttx_attach (UNIT
*uptr
, char *cptr
);
77 t_stat
ttx_detach (UNIT
*uptr
);
78 t_stat
ttx_summ (FILE *st
, UNIT
*uptr
, int32 val
, void *desc
);
79 t_stat
ttx_show (FILE *st
, UNIT
*uptr
, int32 val
, void *desc
);
80 void ttx_enbdis (int32 dis
);
82 /* TTIx data structures
84 ttix_dev TTIx device descriptor
85 ttix_unit TTIx unit descriptor
86 ttix_reg TTIx register list
87 ttix_mod TTIx modifiers list
90 DIB ttix_dib
= { DEV_KJ8
, 8,
91 { &ttix
, &ttox
, &ttix
, &ttox
, &ttix
, &ttox
, &ttix
, &ttox
} };
93 UNIT ttix_unit
= { UDATA (&ttix_svc
, UNIT_IDLE
|UNIT_ATTABLE
, 0), KBD_POLL_WAIT
};
96 { BRDATA (BUF
, ttix_buf
, 8, 8, TTX_LINES
) },
97 { GRDATA (DONE
, dev_done
, 8, TTX_LINES
, INT_V_TTI1
) },
98 { GRDATA (ENABLE
, int_enable
, 8, TTX_LINES
, INT_V_TTI1
) },
99 { GRDATA (INT
, int_req
, 8, TTX_LINES
, INT_V_TTI1
) },
100 { DRDATA (TIME
, ttix_unit
.wait
, 24), REG_NZ
+ PV_LEFT
},
101 { DRDATA (TPS
, ttx_tps
, 10), REG_NZ
+ PV_LEFT
},
102 { ORDATA (DEVNUM
, ttix_dib
.dev
, 6), REG_HRO
},
107 { UNIT_ATT
, UNIT_ATT
, "summary", NULL
, NULL
, &ttx_summ
},
108 { MTAB_XTD
| MTAB_VDV
, 1, NULL
, "DISCONNECT",
109 &tmxr_dscln
, NULL
, &ttx_desc
},
110 { MTAB_XTD
| MTAB_VDV
| MTAB_NMO
, 1, "CONNECTIONS", NULL
,
111 NULL
, &ttx_show
, NULL
},
112 { MTAB_XTD
| MTAB_VDV
| MTAB_NMO
, 0, "STATISTICS", NULL
,
113 NULL
, &ttx_show
, NULL
},
114 { MTAB_XTD
|MTAB_VDV
, 0, "DEVNO", "DEVNO",
115 &set_dev
, &show_dev
, NULL
},
120 "TTIX", &ttix_unit
, ttix_reg
, ttix_mod
,
122 &tmxr_ex
, &tmxr_dep
, &ttix_reset
,
123 NULL
, &ttx_attach
, &ttx_detach
,
124 &ttix_dib
, DEV_NET
| DEV_DISABLE
127 /* TTOx data structures
129 ttox_dev TTOx device descriptor
130 ttox_unit TTOx unit descriptor
131 ttox_reg TTOx register list
135 { UDATA (&ttox_svc
, TT_MODE_UC
, 0), SERIAL_OUT_WAIT
},
136 { UDATA (&ttox_svc
, TT_MODE_UC
, 0), SERIAL_OUT_WAIT
},
137 { UDATA (&ttox_svc
, TT_MODE_UC
, 0), SERIAL_OUT_WAIT
},
138 { UDATA (&ttox_svc
, TT_MODE_UC
, 0), SERIAL_OUT_WAIT
}
142 { BRDATA (BUF
, ttox_buf
, 8, 8, TTX_LINES
) },
143 { GRDATA (DONE
, dev_done
, 8, TTX_LINES
, INT_V_TTO1
) },
144 { GRDATA (ENABLE
, int_enable
, 8, TTX_LINES
, INT_V_TTO1
) },
145 { GRDATA (INT
, int_req
, 8, TTX_LINES
, INT_V_TTO1
) },
146 { URDATA (TIME
, ttox_unit
[0].wait
, 10, 24, 0,
147 TTX_LINES
, PV_LEFT
) },
152 { TT_MODE
, TT_MODE_UC
, "UC", "UC", NULL
},
153 { TT_MODE
, TT_MODE_7B
, "7b", "7B", NULL
},
154 { TT_MODE
, TT_MODE_8B
, "8b", "8B", NULL
},
155 { TT_MODE
, TT_MODE_7P
, "7p", "7P", NULL
},
156 { MTAB_XTD
|MTAB_VUN
, 0, NULL
, "DISCONNECT",
157 &tmxr_dscln
, NULL
, &ttx_desc
},
158 { MTAB_XTD
|MTAB_VUN
|MTAB_NC
, 0, "LOG", "LOG",
159 &tmxr_set_log
, &tmxr_show_log
, &ttx_desc
},
160 { MTAB_XTD
|MTAB_VUN
|MTAB_NC
, 0, NULL
, "NOLOG",
161 &tmxr_set_nolog
, NULL
, &ttx_desc
},
166 "TTOX", ttox_unit
, ttox_reg
, ttox_mod
,
168 NULL
, NULL
, &ttox_reset
,
173 /* Terminal input: IOT routine */
175 int32
ttix (int32 inst
, int32 AC
)
177 int32 pulse
= inst
& 07; /* IOT pulse */
178 int32 ln
= TTX_GETLN (inst
); /* line # */
179 int32 itti
= (INT_TTI1
<< ln
); /* rx intr */
180 int32 itto
= (INT_TTO1
<< ln
); /* tx intr */
182 switch (pulse
) { /* case IR<9:11> */
185 dev_done
= dev_done
& ~itti
; /* clear flag */
186 int_req
= int_req
& ~itti
;
190 return (dev_done
& itti
)? IOT_SKP
+ AC
: AC
;
193 dev_done
= dev_done
& ~itti
; /* clear flag */
194 int_req
= int_req
& ~itti
;
195 return 0; /* clear AC */
198 return (AC
| ttix_buf
[ln
]); /* return buf */
201 if (AC
& 1) int_enable
= int_enable
| (itti
+ itto
);
202 else int_enable
= int_enable
& ~(itti
+ itto
);
203 int_req
= INT_UPDATE
; /* update intr */
207 dev_done
= dev_done
& ~itti
; /* clear flag */
208 int_req
= int_req
& ~itti
;
209 return ttix_buf
[ln
]; /* return buf */
212 return (stop_inst
<< IOT_V_REASON
) + AC
;
220 t_stat
ttix_svc (UNIT
*uptr
)
224 if ((uptr
->flags
& UNIT_ATT
) == 0) return SCPE_OK
; /* attached? */
225 temp
= sim_rtcn_calb (ttx_tps
, TMR_TTX
); /* calibrate */
226 sim_activate (uptr
, temp
); /* continue poll */
227 ln
= tmxr_poll_conn (&ttx_desc
); /* look for connect */
228 if (ln
>= 0) ttx_ldsc
[ln
].rcve
= 1; /* got one? rcv enb*/
229 tmxr_poll_rx (&ttx_desc
); /* poll for input */
230 for (ln
= 0; ln
< TTX_LINES
; ln
++) { /* loop thru lines */
231 if (ttx_ldsc
[ln
].conn
) { /* connected? */
232 if (temp
= tmxr_getc_ln (&ttx_ldsc
[ln
])) { /* get char */
233 if (temp
& SCPE_BREAK
) c
= 0; /* break? */
234 else c
= sim_tt_inpcvt (temp
, TT_GET_MODE (ttox_unit
[ln
].flags
));
236 dev_done
= dev_done
| (INT_TTI1
<< ln
);
237 int_req
= INT_UPDATE
;
246 t_stat
ttix_reset (DEVICE
*dptr
)
250 ttx_enbdis (dptr
->flags
& DEV_DIS
); /* sync enables */
251 if (ttix_unit
.flags
& UNIT_ATT
) { /* if attached, */
252 if (!sim_is_active (&ttix_unit
)) {
253 t
= sim_rtcn_init (ttix_unit
.wait
, TMR_TTX
);
254 sim_activate (&ttix_unit
, t
); /* activate */
257 else sim_cancel (&ttix_unit
); /* else stop */
258 for (ln
= 0; ln
< TTX_LINES
; ln
++) { /* for all lines */
259 ttix_buf
[ln
] = 0; /* clear buf, */
260 itto
= (INT_TTI1
<< ln
); /* interrupt */
261 dev_done
= dev_done
& ~itto
; /* clr done, int */
262 int_req
= int_req
& ~itto
;
263 int_enable
= int_enable
| itto
; /* set enable */
268 /* Terminal output: IOT routine */
270 int32
ttox (int32 inst
, int32 AC
)
272 int32 pulse
= inst
& 07; /* pulse */
273 int32 ln
= TTX_GETLN (inst
); /* line # */
274 int32 itti
= (INT_TTI1
<< ln
); /* rx intr */
275 int32 itto
= (INT_TTO1
<< ln
); /* tx intr */
277 switch (pulse
) { /* case IR<9:11> */
280 dev_done
= dev_done
| itto
; /* set flag */
281 int_req
= INT_UPDATE
; /* update intr */
285 return (dev_done
& itto
)? IOT_SKP
+ AC
: AC
;
288 dev_done
= dev_done
& ~itto
; /* clear flag */
289 int_req
= int_req
& ~itto
; /* clear intr */
293 return (int_req
& (itti
| itto
))? IOT_SKP
+ AC
: AC
;
296 dev_done
= dev_done
& ~itto
; /* clear flag */
297 int_req
= int_req
& ~itto
; /* clear int req */
299 sim_activate (&ttox_unit
[ln
], ttox_unit
[ln
].wait
); /* activate */
300 ttox_buf
[ln
] = AC
& 0377; /* load buffer */
304 return (stop_inst
<< IOT_V_REASON
) + AC
;
312 t_stat
ttox_svc (UNIT
*uptr
)
314 int32 c
, ln
= uptr
- ttox_unit
; /* line # */
316 if (ttx_ldsc
[ln
].conn
) { /* connected? */
317 if (ttx_ldsc
[ln
].xmte
) { /* tx enabled? */
318 TMLN
*lp
= &ttx_ldsc
[ln
]; /* get line */
319 c
= sim_tt_outcvt (ttox_buf
[ln
], TT_GET_MODE (ttox_unit
[ln
].flags
));
320 if (c
>= 0) tmxr_putc_ln (lp
, c
); /* output char */
321 tmxr_poll_tx (&ttx_desc
); /* poll xmt */
324 tmxr_poll_tx (&ttx_desc
); /* poll xmt */
325 sim_activate (uptr
, ttox_unit
[ln
].wait
); /* wait */
329 dev_done
= dev_done
| (INT_TTO1
<< ln
); /* set done */
330 int_req
= INT_UPDATE
; /* update intr */
336 t_stat
ttox_reset (DEVICE
*dptr
)
340 ttx_enbdis (dptr
->flags
& DEV_DIS
); /* sync enables */
341 for (ln
= 0; ln
< TTX_LINES
; ln
++) { /* for all lines */
342 ttox_buf
[ln
] = 0; /* clear buf */
343 itto
= (INT_TTO1
<< ln
); /* interrupt */
344 dev_done
= dev_done
& ~itto
; /* clr done, int */
345 int_req
= int_req
& ~itto
;
346 int_enable
= int_enable
| itto
; /* set enable */
347 sim_cancel (&ttox_unit
[ln
]); /* deactivate */
352 /* Attach master unit */
354 t_stat
ttx_attach (UNIT
*uptr
, char *cptr
)
359 r
= tmxr_attach (&ttx_desc
, uptr
, cptr
); /* attach */
360 if (r
!= SCPE_OK
) return r
; /* error */
361 t
= sim_rtcn_init (ttix_unit
.wait
, TMR_TTX
); /* init calib */
362 sim_activate (uptr
, t
); /* start poll */
366 /* Detach master unit */
368 t_stat
ttx_detach (UNIT
*uptr
)
373 r
= tmxr_detach (&ttx_desc
, uptr
); /* detach */
374 for (i
= 0; i
< TTX_LINES
; i
++) /* all lines, */
375 ttx_ldsc
[i
].rcve
= 0; /* disable rcv */
376 sim_cancel (uptr
); /* stop poll */
380 /* Show summary processor */
382 t_stat
ttx_summ (FILE *st
, UNIT
*uptr
, int32 val
, void *desc
)
386 for (i
= t
= 0; i
< TTX_LINES
; i
++) t
= t
+ (ttx_ldsc
[i
].conn
!= 0);
387 if (t
== 1) fprintf (st
, "1 connection");
388 else fprintf (st
, "%d connections", t
);
392 /* SHOW CONN/STAT processor */
394 t_stat
ttx_show (FILE *st
, UNIT
*uptr
, int32 val
, void *desc
)
398 for (i
= t
= 0; i
< TTX_LINES
; i
++) t
= t
+ (ttx_ldsc
[i
].conn
!= 0);
400 for (i
= 0; i
< TTX_LINES
; i
++) {
401 if (ttx_ldsc
[i
].conn
) {
402 if (val
) tmxr_fconns (st
, &ttx_ldsc
[i
], i
);
403 else tmxr_fstats (st
, &ttx_ldsc
[i
], i
);
407 else fprintf (st
, "all disconnected\n");
411 /* Enable/disable device */
413 void ttx_enbdis (int32 dis
)
416 ttix_dev
.flags
= ttox_dev
.flags
| DEV_DIS
;
417 ttox_dev
.flags
= ttox_dev
.flags
| DEV_DIS
;
420 ttix_dev
.flags
= ttix_dev
.flags
& ~DEV_DIS
;
421 ttox_dev
.flags
= ttox_dev
.flags
& ~DEV_DIS
;