| 1 | /* nova_tt.c: NOVA console terminal simulator\r |
| 2 | \r |
| 3 | Copyright (c) 1993-2008, Robert M. Supnik\r |
| 4 | \r |
| 5 | Permission is hereby granted, free of charge, to any person obtaining a\r |
| 6 | copy of this software and associated documentation files (the "Software"),\r |
| 7 | to deal in the Software without restriction, including without limitation\r |
| 8 | the rights to use, copy, modify, merge, publish, distribute, sublicense,\r |
| 9 | and/or sell copies of the Software, and to permit persons to whom the\r |
| 10 | Software is furnished to do so, subject to the following conditions:\r |
| 11 | \r |
| 12 | The above copyright notice and this permission notice shall be included in\r |
| 13 | all copies or substantial portions of the Software.\r |
| 14 | \r |
| 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r |
| 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r |
| 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r |
| 18 | ROBERT M SUPNIK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r |
| 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r |
| 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r |
| 21 | \r |
| 22 | Except as contained in this notice, the name of Robert M Supnik shall not be\r |
| 23 | used in advertising or otherwise to promote the sale, use or other dealings\r |
| 24 | in this Software without prior written authorization from Robert M Supnik.\r |
| 25 | \r |
| 26 | tti terminal input\r |
| 27 | tto terminal output\r |
| 28 | \r |
| 29 | 04-Jul-07 BKR fixed Dasher CR/LF swap function in 'tti_svc()',\r |
| 30 | DEV_SET/CLR macros now used,\r |
| 31 | TTO device may now be DISABLED\r |
| 32 | 29-Dec-03 RMS Added console backpressure support\r |
| 33 | 25-Apr-03 RMS Revised for extended file support\r |
| 34 | 05-Jan-02 RMS Fixed calling sequence for setmod\r |
| 35 | 03-Oct-02 RMS Added DIBs\r |
| 36 | 30-May-02 RMS Widened POS to 32b\r |
| 37 | 30-Nov-01 RMS Added extended SET/SHOW support\r |
| 38 | 17-Sep-01 RMS Removed multiconsole support\r |
| 39 | 07-Sep-01 RMS Moved function prototypes\r |
| 40 | 31-May-01 RMS Added multiconsole support\r |
| 41 | \r |
| 42 | Notes:\r |
| 43 | - TTO output is always masked to 7 bits in this rev\r |
| 44 | - TTO "Dasher" attribute sends '\b' to console instead of '\031'\r |
| 45 | - TTO may be disabled\r |
| 46 | - TTI input is always masked to 7 bits in this rev\r |
| 47 | - TTI "Dasher" attribute swaps <CR> and <LF>\r |
| 48 | - TTI may not be disabled\r |
| 49 | */\r |
| 50 | \r |
| 51 | #include "nova_defs.h"\r |
| 52 | \r |
| 53 | #define UNIT_V_DASHER (UNIT_V_UF + 0) /* Dasher mode */\r |
| 54 | #define UNIT_DASHER (1 << UNIT_V_DASHER)\r |
| 55 | \r |
| 56 | extern int32 int_req, dev_busy, dev_done, dev_disable;\r |
| 57 | \r |
| 58 | int32 tti (int32 pulse, int32 code, int32 AC);\r |
| 59 | int32 tto (int32 pulse, int32 code, int32 AC);\r |
| 60 | t_stat tti_svc (UNIT *uptr);\r |
| 61 | t_stat tto_svc (UNIT *uptr);\r |
| 62 | t_stat tti_reset (DEVICE *dptr);\r |
| 63 | t_stat tto_reset (DEVICE *dptr);\r |
| 64 | t_stat ttx_setmod (UNIT *uptr, int32 val, char *cptr, void *desc);\r |
| 65 | \r |
| 66 | /* TTI data structures\r |
| 67 | \r |
| 68 | tti_dev TTI device descriptor\r |
| 69 | tti_unit TTI unit descriptor\r |
| 70 | tti_reg TTI register list\r |
| 71 | ttx_mod TTI/TTO modifiers list\r |
| 72 | */\r |
| 73 | \r |
| 74 | DIB tti_dib = { DEV_TTI, INT_TTI, PI_TTI, &tti };\r |
| 75 | \r |
| 76 | UNIT tti_unit = { UDATA (&tti_svc, 0, 0), KBD_POLL_WAIT };\r |
| 77 | \r |
| 78 | REG tti_reg[] = {\r |
| 79 | { ORDATA (BUF, tti_unit.buf, 8) },\r |
| 80 | { FLDATA (BUSY, dev_busy, INT_V_TTI) },\r |
| 81 | { FLDATA (DONE, dev_done, INT_V_TTI) },\r |
| 82 | { FLDATA (DISABLE, dev_disable, INT_V_TTI) },\r |
| 83 | { FLDATA (INT, int_req, INT_V_TTI) },\r |
| 84 | { DRDATA (POS, tti_unit.pos, T_ADDR_W), PV_LEFT },\r |
| 85 | { DRDATA (TIME, tti_unit.wait, 24), REG_NZ + PV_LEFT },\r |
| 86 | { NULL }\r |
| 87 | };\r |
| 88 | \r |
| 89 | MTAB ttx_mod[] = {\r |
| 90 | { UNIT_DASHER, 0, "ANSI", "ANSI", &ttx_setmod },\r |
| 91 | { UNIT_DASHER, UNIT_DASHER, "Dasher", "DASHER", &ttx_setmod },\r |
| 92 | { 0 }\r |
| 93 | } ;\r |
| 94 | \r |
| 95 | DEVICE tti_dev = {\r |
| 96 | "TTI", &tti_unit, tti_reg, ttx_mod,\r |
| 97 | 1, 10, 31, 1, 8, 8,\r |
| 98 | NULL, NULL, &tti_reset,\r |
| 99 | NULL, NULL, NULL,\r |
| 100 | &tti_dib, 0\r |
| 101 | };\r |
| 102 | \r |
| 103 | /* TTO data structures\r |
| 104 | \r |
| 105 | tto_dev TTO device descriptor\r |
| 106 | tto_unit TTO unit descriptor\r |
| 107 | tto_reg TTO register list\r |
| 108 | */\r |
| 109 | \r |
| 110 | DIB tto_dib = { DEV_TTO, INT_TTO, PI_TTO, &tto };\r |
| 111 | \r |
| 112 | UNIT tto_unit = { UDATA (&tto_svc, 0, 0), SERIAL_OUT_WAIT };\r |
| 113 | \r |
| 114 | REG tto_reg[] = {\r |
| 115 | { ORDATA (BUF, tto_unit.buf, 8) },\r |
| 116 | { FLDATA (BUSY, dev_busy, INT_V_TTO) },\r |
| 117 | { FLDATA (DONE, dev_done, INT_V_TTO) },\r |
| 118 | { FLDATA (DISABLE, dev_disable, INT_V_TTO) },\r |
| 119 | { FLDATA (INT, int_req, INT_V_TTO) },\r |
| 120 | { DRDATA (POS, tto_unit.pos, T_ADDR_W), PV_LEFT },\r |
| 121 | { DRDATA (TIME, tto_unit.wait, 24), PV_LEFT },\r |
| 122 | { NULL }\r |
| 123 | };\r |
| 124 | \r |
| 125 | DEVICE tto_dev = {\r |
| 126 | "TTO", &tto_unit, tto_reg, ttx_mod,\r |
| 127 | 1, 10, 31, 1, 8, 8,\r |
| 128 | NULL, NULL, &tto_reset,\r |
| 129 | NULL, NULL, NULL,\r |
| 130 | &tto_dib, DEV_DISABLE\r |
| 131 | };\r |
| 132 | \r |
| 133 | /* Terminal input: IOT routine */\r |
| 134 | \r |
| 135 | int32 tti (int32 pulse, int32 code, int32 AC)\r |
| 136 | {\r |
| 137 | int32 iodata;\r |
| 138 | \r |
| 139 | \r |
| 140 | if (code == ioDIA)\r |
| 141 | iodata = tti_unit.buf & 0377;\r |
| 142 | else iodata = 0;\r |
| 143 | \r |
| 144 | switch (pulse)\r |
| 145 | { /* decode IR<8:9> */\r |
| 146 | case iopS: /* start */\r |
| 147 | DEV_SET_BUSY( INT_TTI ) ;\r |
| 148 | DEV_CLR_DONE( INT_TTI ) ;\r |
| 149 | DEV_UPDATE_INTR ;\r |
| 150 | break;\r |
| 151 | \r |
| 152 | case iopC: /* clear */\r |
| 153 | DEV_CLR_BUSY( INT_TTI ) ;\r |
| 154 | DEV_CLR_DONE( INT_TTI ) ;\r |
| 155 | DEV_UPDATE_INTR ;\r |
| 156 | break;\r |
| 157 | } /* end switch */\r |
| 158 | \r |
| 159 | return iodata;\r |
| 160 | }\r |
| 161 | \r |
| 162 | /* Unit service */\r |
| 163 | \r |
| 164 | t_stat tti_svc (UNIT *uptr)\r |
| 165 | {\r |
| 166 | int32 temp;\r |
| 167 | \r |
| 168 | sim_activate (&tti_unit, tti_unit.wait); /* continue poll */\r |
| 169 | if ((temp = sim_poll_kbd ()) < SCPE_KFLAG)\r |
| 170 | return temp; /* no char or error? */\r |
| 171 | tti_unit.buf = temp & 0177;\r |
| 172 | if (tti_unit.flags & UNIT_DASHER) {\r |
| 173 | if (tti_unit.buf == '\r')\r |
| 174 | tti_unit.buf = '\n'; /* Dasher: cr -> nl */\r |
| 175 | else if (tti_unit.buf == '\n')\r |
| 176 | tti_unit.buf = '\r' ; /* Dasher: nl -> cr */\r |
| 177 | }\r |
| 178 | DEV_CLR_BUSY( INT_TTI ) ;\r |
| 179 | DEV_SET_DONE( INT_TTI ) ;\r |
| 180 | DEV_UPDATE_INTR ;\r |
| 181 | ++(uptr->pos) ;\r |
| 182 | return SCPE_OK;\r |
| 183 | }\r |
| 184 | \r |
| 185 | /* Reset routine */\r |
| 186 | \r |
| 187 | t_stat tti_reset (DEVICE *dptr)\r |
| 188 | {\r |
| 189 | tti_unit.buf = 0; /* <not DG compatible> */\r |
| 190 | DEV_CLR_BUSY( INT_TTI ) ;\r |
| 191 | DEV_CLR_DONE( INT_TTI ) ;\r |
| 192 | DEV_UPDATE_INTR ;\r |
| 193 | sim_activate (&tti_unit, tti_unit.wait); /* activate unit */\r |
| 194 | return SCPE_OK;\r |
| 195 | }\r |
| 196 | \r |
| 197 | /* Terminal output: IOT routine */\r |
| 198 | \r |
| 199 | int32 tto (int32 pulse, int32 code, int32 AC)\r |
| 200 | {\r |
| 201 | if (code == ioDOA)\r |
| 202 | tto_unit.buf = AC & 0377; \r |
| 203 | \r |
| 204 | switch (pulse)\r |
| 205 | { /* decode IR<8:9> */\r |
| 206 | case iopS: /* start */\r |
| 207 | DEV_SET_BUSY( INT_TTO ) ;\r |
| 208 | DEV_CLR_DONE( INT_TTO ) ;\r |
| 209 | DEV_UPDATE_INTR ;\r |
| 210 | sim_activate (&tto_unit, tto_unit.wait); /* activate unit */\r |
| 211 | break;\r |
| 212 | \r |
| 213 | case iopC: /* clear */\r |
| 214 | DEV_CLR_BUSY( INT_TTO ) ;\r |
| 215 | DEV_CLR_DONE( INT_TTO ) ;\r |
| 216 | DEV_UPDATE_INTR ;\r |
| 217 | sim_cancel (&tto_unit); /* deactivate unit */\r |
| 218 | break;\r |
| 219 | } /* end switch */\r |
| 220 | return 0;\r |
| 221 | }\r |
| 222 | \r |
| 223 | \r |
| 224 | /* Unit service */\r |
| 225 | \r |
| 226 | t_stat tto_svc (UNIT *uptr)\r |
| 227 | {\r |
| 228 | int32 c;\r |
| 229 | t_stat r;\r |
| 230 | \r |
| 231 | c = tto_unit.buf & 0177;\r |
| 232 | if ((tto_unit.flags & UNIT_DASHER) && (c == 031))\r |
| 233 | c = '\b';\r |
| 234 | if ((r = sim_putchar_s (c)) != SCPE_OK) { /* output; error? */\r |
| 235 | sim_activate (uptr, uptr->wait); /* try again */\r |
| 236 | return ((r == SCPE_STALL)? SCPE_OK : r); /* !stall? report */\r |
| 237 | }\r |
| 238 | DEV_CLR_BUSY( INT_TTO ) ;\r |
| 239 | DEV_SET_DONE( INT_TTO ) ;\r |
| 240 | DEV_UPDATE_INTR ;\r |
| 241 | ++(tto_unit.pos);\r |
| 242 | return SCPE_OK;\r |
| 243 | }\r |
| 244 | \r |
| 245 | /* Reset routine */\r |
| 246 | \r |
| 247 | t_stat tto_reset (DEVICE *dptr)\r |
| 248 | {\r |
| 249 | tto_unit.buf = 0; /* <not DG compatible!> */\r |
| 250 | DEV_CLR_BUSY( INT_TTO ) ;\r |
| 251 | DEV_CLR_DONE( INT_TTO ) ;\r |
| 252 | DEV_UPDATE_INTR ;\r |
| 253 | sim_cancel (&tto_unit); /* deactivate unit */\r |
| 254 | return SCPE_OK;\r |
| 255 | }\r |
| 256 | \r |
| 257 | t_stat ttx_setmod (UNIT *uptr, int32 val, char *cptr, void *desc)\r |
| 258 | {\r |
| 259 | tti_unit.flags = (tti_unit.flags & ~UNIT_DASHER) | val;\r |
| 260 | tto_unit.flags = (tto_unit.flags & ~UNIT_DASHER) | val;\r |
| 261 | return SCPE_OK;\r |
| 262 | }\r |