First Commit of my working state
[simh.git] / I1401 / i1401_iq.c
1 /* i1401_iq.c: IBM 1407 inquiry terminal
2
3 Copyright (c) 1993-2005, Robert M. Supnik
4
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:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
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.
21
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.
25
26 inq 1407 inquiry terminal
27
28 20-Sep-05 RMS Revised for new code tables
29 22-Dec-02 RMS Added break support
30 07-Sep-01 RMS Moved function prototypes
31 14-Apr-99 RMS Changed t_addr to unsigned
32 */
33
34 #include "i1401_defs.h"
35 #include <ctype.h>
36
37 #define UNIT_V_PCH (UNIT_V_UF + 0) /* output conv */
38 #define UNIT_PCH (1 << UNIT_V_PCH)
39
40 extern volatile int32 stop_cpu;
41 extern uint8 M[];
42 extern int32 BS, iochk, ind[64];
43 extern UNIT cpu_unit;
44 extern t_bool conv_old;
45
46 int32 inq_char = 033; /* request inq */
47 t_stat inq_svc (UNIT *uptr);
48 t_stat inq_reset (DEVICE *dptr);
49
50 void puts_tty (char *cptr);
51
52 /* INQ data structures
53
54 inq_dev INQ device descriptor
55 inq_unit INQ unit descriptor
56 inq_reg INQ register list
57 */
58
59 UNIT inq_unit = { UDATA (&inq_svc, 0, 0), KBD_POLL_WAIT };
60
61 REG inq_reg[] = {
62 { ORDATA (INQC, inq_char, 7) },
63 { FLDATA (INR, ind[IN_INR], 0) },
64 { FLDATA (INC, ind[IN_INC], 0) },
65 { DRDATA (TIME, inq_unit.wait, 24), REG_NZ + PV_LEFT },
66 { NULL }
67 };
68
69 MTAB inq_mod[] = {
70 { UNIT_PCH, 0, "business set", "BUSINESS" },
71 { UNIT_PCH, UNIT_PCH, "Fortran set", "FORTRAN" },
72 { 0 }
73 };
74
75 DEVICE inq_dev = {
76 "INQ", &inq_unit, inq_reg, inq_mod,
77 1, 10, 31, 1, 8, 7,
78 NULL, NULL, &inq_reset,
79 NULL, NULL, NULL
80 };
81
82 /* Terminal I/O
83
84 Modifiers have not been checked; legal modifiers are R and W
85 */
86
87 t_stat inq_io (int32 flag, int32 mod)
88 {
89 int32 i, t, wm_seen = 0;
90 t_bool use_h = inq_unit.flags & UNIT_PCH;
91
92 ind[IN_INC] = 0; /* clear inq clear */
93 switch (mod) { /* case on mod */
94
95 case BCD_R: /* input */
96 /* if (ind[IN_INR] == 0) return SCPE_OK; /* return if no req */
97 ind[IN_INR] = 0; /* clear req */
98 puts_tty ("[Enter]\r\n"); /* prompt */
99 for (i = 0; M[BS] != (BCD_GRPMRK + WM); i++) { /* until GM + WM */
100 while (((t = sim_poll_kbd ()) == SCPE_OK) ||
101 (t & SCPE_BREAK)) {
102 if (stop_cpu) return SCPE_STOP; /* interrupt? */
103 }
104 if (t < SCPE_KFLAG) return t; /* if not char, err */
105 t = t & 0177;
106 if ((t == '\r') || (t == '\n')) break;
107 if (t == inq_char) { /* cancel? */
108 ind[IN_INC] = 1; /* set indicator */
109 puts_tty ("\r\n[Canceled]\r\n");
110 return SCPE_OK;
111 }
112 if (i && ((i % INQ_WIDTH) == 0)) puts_tty ("\r\n");
113 sim_putchar (t); /* echo */
114 if (flag == MD_WM) { /* word mark mode? */
115 if ((t == '~') && (wm_seen == 0)) wm_seen = WM;
116 else {
117 M[BS] = wm_seen | ascii2bcd (t);
118 wm_seen = 0;
119 }
120 }
121 else M[BS] = (M[BS] & WM) | ascii2bcd (t);
122 if (!wm_seen) BS++;
123 if (ADDR_ERR (BS)) {
124 BS = BA | (BS % MAXMEMSIZE);
125 return STOP_NXM;
126 }
127 }
128 puts_tty ("\r\n");
129 M[BS++] = BCD_GRPMRK + WM;
130 break;
131
132 case BCD_W: /* output */
133 for (i = 0; (t = M[BS++]) != (BCD_GRPMRK + WM); i++) {
134 if ((flag == MD_WM) && (t & WM)) {
135 if (i && ((i % INQ_WIDTH) == 0)) puts_tty ("\r\n");
136 if (conv_old) sim_putchar ('~');
137 else sim_putchar ('`');
138 }
139 if (i && ((i % INQ_WIDTH) == 0)) puts_tty ("\r\n");
140 sim_putchar (bcd2ascii (t & CHAR, use_h));
141 if (ADDR_ERR (BS)) {
142 BS = BA | (BS % MAXMEMSIZE);
143 return STOP_NXM;
144 }
145 }
146 puts_tty ("\r\n");
147 break;
148
149 default: /* invalid mod */
150 return STOP_INVM;
151 }
152
153 return SCPE_OK;
154 }
155
156 /* Unit service - polls for WRU or inquiry request */
157
158 t_stat inq_svc (UNIT *uptr)
159 {
160 int32 temp;
161
162 sim_activate (&inq_unit, inq_unit.wait); /* continue poll */
163 if ((temp = sim_poll_kbd ()) < SCPE_KFLAG) return temp; /* no char or error? */
164 if ((temp & 0177) == inq_char) ind[IN_INR] = 1; /* set indicator */
165 return SCPE_OK;
166 }
167
168 /* Output multiple characters */
169
170 void puts_tty (char *cptr)
171 {
172 if (cptr == NULL) return;
173 while (*cptr != 0) sim_putchar (*cptr++);
174 return;
175 }
176
177 /* Reset routine */
178
179 t_stat inq_reset (DEVICE *dptr)
180 {
181 ind[IN_INR] = ind[IN_INC] = 0; /* clear indicators */
182 sim_activate (&inq_unit, inq_unit.wait); /* activate poll */
183 return SCPE_OK;
184 }