1 /* i1401_iq.c: IBM 1407 inquiry terminal
3 Copyright (c) 1993-2005, 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 inq 1407 inquiry terminal
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
34 #include "i1401_defs.h"
37 #define UNIT_V_PCH (UNIT_V_UF + 0) /* output conv */
38 #define UNIT_PCH (1 << UNIT_V_PCH)
40 extern volatile int32 stop_cpu
;
42 extern int32 BS
, iochk
, ind
[64];
44 extern t_bool conv_old
;
46 int32 inq_char
= 033; /* request inq */
47 t_stat
inq_svc (UNIT
*uptr
);
48 t_stat
inq_reset (DEVICE
*dptr
);
50 void puts_tty (char *cptr
);
52 /* INQ data structures
54 inq_dev INQ device descriptor
55 inq_unit INQ unit descriptor
56 inq_reg INQ register list
59 UNIT inq_unit
= { UDATA (&inq_svc
, 0, 0), KBD_POLL_WAIT
};
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
},
70 { UNIT_PCH
, 0, "business set", "BUSINESS" },
71 { UNIT_PCH
, UNIT_PCH
, "Fortran set", "FORTRAN" },
76 "INQ", &inq_unit
, inq_reg
, inq_mod
,
78 NULL
, NULL
, &inq_reset
,
84 Modifiers have not been checked; legal modifiers are R and W
87 t_stat
inq_io (int32 flag
, int32 mod
)
89 int32 i
, t
, wm_seen
= 0;
90 t_bool use_h
= inq_unit
.flags
& UNIT_PCH
;
92 ind
[IN_INC
] = 0; /* clear inq clear */
93 switch (mod
) { /* case on mod */
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
) ||
102 if (stop_cpu
) return SCPE_STOP
; /* interrupt? */
104 if (t
< SCPE_KFLAG
) return t
; /* if not char, err */
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");
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
;
117 M
[BS
] = wm_seen
| ascii2bcd (t
);
121 else M
[BS
] = (M
[BS
] & WM
) | ascii2bcd (t
);
124 BS
= BA
| (BS
% MAXMEMSIZE
);
129 M
[BS
++] = BCD_GRPMRK
+ WM
;
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 ('`');
139 if (i
&& ((i
% INQ_WIDTH
) == 0)) puts_tty ("\r\n");
140 sim_putchar (bcd2ascii (t
& CHAR
, use_h
));
142 BS
= BA
| (BS
% MAXMEMSIZE
);
149 default: /* invalid mod */
156 /* Unit service - polls for WRU or inquiry request */
158 t_stat
inq_svc (UNIT
*uptr
)
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 */
168 /* Output multiple characters */
170 void puts_tty (char *cptr
)
172 if (cptr
== NULL
) return;
173 while (*cptr
!= 0) sim_putchar (*cptr
++);
179 t_stat
inq_reset (DEVICE
*dptr
)
181 ind
[IN_INR
] = ind
[IN_INC
] = 0; /* clear indicators */
182 sim_activate (&inq_unit
, inq_unit
.wait
); /* activate poll */