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