8923943c3905de79fded8206735624d9540cda5a
1 /* hp2100_stddev.c: HP2100 standard devices simulator
3 Copyright (c) 1993-2008, 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 ptr 12597A-002 paper tape reader interface
27 ptp 12597A-005 paper tape punch interface
28 tty 12531C buffered teleprinter interface
29 clk 12539C time base generator
31 25-Apr-08 JDB Changed TTY output wait from 100 to 200 for MSU BASIC
32 18-Apr-08 JDB Removed redundant control char handling definitions
33 14-Apr-08 JDB Changed TTY console poll to 10 msec. real time
34 Synchronized CLK with TTY if set for 10 msec.
35 Added UNIT_IDLE to TTY and CLK
36 09-Jan-08 JDB Fixed PTR trailing null counter for tape re-read
37 31-Dec-07 JDB Added IPTICK register to CLK to display CPU instr/tick
38 Corrected and verified ioCRS actions
39 28-Dec-06 JDB Added ioCRS state to I/O decoders
40 22-Nov-05 RMS Revised for new terminal processing routines
41 13-Sep-04 JDB Added paper tape loop mode, DIAG/READER modifiers to PTR
42 Added PV_LEFT to PTR TRLLIM register
43 Modified CLK to permit disable
44 15-Aug-04 RMS Added tab to control char set (from Dave Bryan)
45 14-Jul-04 RMS Generalized handling of control char echoing
47 26-Apr-04 RMS Fixed SFS x,C and SFC x,C
48 Fixed SR setting in IBL
49 Fixed input behavior during typeout for RTE-IV
50 Suppressed nulls on TTY output for RTE-IV
51 Implemented DMA SRQ (follows FLG)
52 29-Mar-03 RMS Added support for console backpressure
53 25-Apr-03 RMS Added extended file support
54 22-Dec-02 RMS Added break support
55 01-Nov-02 RMS Revised BOOT command for IBL ROMs
56 Fixed bug in TTY reset, TTY starts in input mode
57 Fixed bug in TTY mode OTA, stores data as well
58 Fixed clock to add calibration, proper start/stop
59 Added UC option to TTY output
60 30-May-02 RMS Widened POS to 32b
61 22-Mar-02 RMS Revised for dynamically allocated memory
62 03-Nov-01 RMS Changed DEVNO to use extended SET/SHOW
63 29-Nov-01 RMS Added read only unit support
64 24-Nov-01 RMS Changed TIME to an array
65 07-Sep-01 RMS Moved function prototypes
66 21-Nov-00 RMS Fixed flag, buffer power up state
67 Added status input for ptp, tty
68 15-Oct-00 RMS Added dynamic device number support
70 The reader and punch, like most HP devices, have a command flop. The
71 teleprinter and clock do not.
73 Reader diagnostic mode simulates a tape loop by rewinding the tape image file
74 upon EOF. Normal mode EOF action is to supply TRLLIM nulls and then either
75 return SCPE_IOERR or SCPE_OK without setting the device flag.
77 To support CPU idling, the teleprinter interface (which doubles as the
78 simulator console) polls for input using a calibrated timer with a ten
79 millisecond period. Other polled-keyboard input devices (multiplexers and
80 the BACI card) synchronize with the console poll to ensure maximum available
81 idle time. The console poll is guaranteed to run, as the TTY device cannot
84 The clock (time base generator) autocalibrates. If the CLK is set to a ten
85 millisecond period (e.g., as under RTE), it is synchronized to the console
86 poll. Otherwise (e.g., as under DOS or TSB, which use 100 millisecond
87 periods), it runs asynchronously. If the specified clock frequency is below
88 10Hz, the clock service routine runs at 10Hz and counts down a repeat counter
89 before generating an interrupt. Autocalibration will not work if the clock
90 is running at 1Hz or less.
92 Clock diagnostic mode corresponds to inserting jumper W2 on the 12539C.
93 This turns off autocalibration and divides the longest time intervals down
94 by 10**3. The clk_time values were chosen to allow the diagnostic to
95 pass its clock calibration test.
98 - 2748B Tape Reader Operating and Service Manual (02748-90041, Oct-1977)
99 - 12597A 8-Bit Duplex Register Interface Kit Operating and Service Manual
100 (12597-9002, Sep-1974)
101 - 12531C Buffered Teleprinter Interface Kit Operating and Service Manual
102 (12531-90033, Nov-1972)
103 - 12539C Time Base Generator Interface Kit Operating and Service Manual
104 (12539-90008, Jan-1975)
107 #include "hp2100_defs.h"
109 #define TTY_OUT_WAIT 200 /* TTY output wait */
111 #define UNIT_V_DIAG (TTUF_V_UF + 0) /* diag mode */
112 #define UNIT_V_AUTOLF (TTUF_V_UF + 1) /* auto linefeed */
113 #define UNIT_DIAG (1 << UNIT_V_DIAG)
114 #define UNIT_AUTOLF (1 << UNIT_V_AUTOLF)
116 #define PTP_LOW 0000040 /* low tape */
117 #define TM_MODE 0100000 /* mode change */
118 #define TM_KBD 0040000 /* enable keyboard */
119 #define TM_PRI 0020000 /* enable printer */
120 #define TM_PUN 0010000 /* enable punch */
121 #define TP_BUSY 0100000 /* busy */
123 #define CLK_V_ERROR 4 /* clock overrun */
124 #define CLK_ERROR (1 << CLK_V_ERROR)
126 extern uint32 PC
, SR
;
127 extern uint32 dev_cmd
[2], dev_ctl
[2], dev_flg
[2], dev_fbf
[2], dev_srq
[2];
129 int32 ptr_stopioe
= 0; /* stop on error */
130 int32 ptr_trlcnt
= 0; /* trailer counter */
131 int32 ptr_trllim
= 40; /* trailer to add */
132 int32 ptp_stopioe
= 0;
133 int32 ttp_stopioe
= 0;
134 int32 tty_buf
= 0; /* tty buffer */
135 int32 tty_mode
= 0; /* tty mode */
136 int32 tty_shin
= 0377; /* tty shift in */
137 int32 tty_lf
= 0; /* lf flag */
138 int32 clk_select
= 0; /* clock time select */
139 int32 clk_error
= 0; /* clock error */
140 int32 clk_ctr
= 0; /* clock counter */
141 int32 clk_time
[8] = { /* clock intervals */
142 155, 1550, 15500, 155000, 155000, 155000, 155000, 155000
144 int32 clk_tps
[8] = { /* clock tps */
145 10000, 1000, 100, 10, 10, 10, 10, 10
147 int32 clk_rpt
[8] = { /* number of repeats */
148 1, 1, 1, 1, 10, 100, 1000, 10000
150 uint32 clk_tick
= 0; /* instructions per tick */
152 DEVICE ptr_dev
, ptp_dev
, tty_dev
, clk_dev
;
153 int32
ptrio (int32 inst
, int32 IR
, int32 dat
);
154 t_stat
ptr_svc (UNIT
*uptr
);
155 t_stat
ptr_attach (UNIT
*uptr
, char *cptr
);
156 t_stat
ptr_reset (DEVICE
*dptr
);
157 t_stat
ptr_boot (int32 unitno
, DEVICE
*dptr
);
158 int32
ptpio (int32 inst
, int32 IR
, int32 dat
);
159 t_stat
ptp_svc (UNIT
*uptr
);
160 t_stat
ptp_reset (DEVICE
*dptr
);
161 int32
ttyio (int32 inst
, int32 IR
, int32 dat
);
162 t_stat
tti_svc (UNIT
*uptr
);
163 t_stat
tto_svc (UNIT
*uptr
);
164 t_stat
tty_reset (DEVICE
*dptr
);
165 t_stat
tty_set_opt (UNIT
*uptr
, int32 val
, char *cptr
, void *desc
);
166 t_stat
tty_set_alf (UNIT
*uptr
, int32 val
, char *cptr
, void *desc
);
167 int32
clkio (int32 inst
, int32 IR
, int32 dat
);
168 t_stat
clk_svc (UNIT
*uptr
);
169 t_stat
clk_reset (DEVICE
*dptr
);
170 int32
clk_delay (int32 flg
);
171 t_stat
tto_out (int32 c
);
172 t_stat
ttp_out (int32 c
);
174 /* PTR data structures
176 ptr_dev PTR device descriptor
177 ptr_unit PTR unit descriptor
178 ptr_mod PTR modifiers
179 ptr_reg PTR register list
182 DIB ptr_dib
= { PTR
, 0, 0, 0, 0, 0, &ptrio
};
185 UDATA (&ptr_svc
, UNIT_SEQ
+UNIT_ATTABLE
+UNIT_ROABLE
, 0),
190 { ORDATA (BUF
, ptr_unit
.buf
, 8) },
191 { FLDATA (CMD
, ptr_dib
.cmd
, 0) },
192 { FLDATA (CTL
, ptr_dib
.ctl
, 0) },
193 { FLDATA (FLG
, ptr_dib
.flg
, 0) },
194 { FLDATA (FBF
, ptr_dib
.fbf
, 0) },
195 { FLDATA (SRQ
, ptr_dib
.srq
, 0) },
196 { DRDATA (TRLCTR
, ptr_trlcnt
, 8), REG_HRO
},
197 { DRDATA (TRLLIM
, ptr_trllim
, 8), PV_LEFT
},
198 { DRDATA (POS
, ptr_unit
.pos
, T_ADDR_W
), PV_LEFT
},
199 { DRDATA (TIME
, ptr_unit
.wait
, 24), PV_LEFT
},
200 { FLDATA (STOP_IOE
, ptr_stopioe
, 0) },
201 { ORDATA (DEVNO
, ptr_dib
.devno
, 6), REG_HRO
},
206 { UNIT_DIAG
, UNIT_DIAG
, "diagnostic mode", "DIAG", NULL
},
207 { UNIT_DIAG
, 0, "reader mode", "READER", NULL
},
208 { MTAB_XTD
| MTAB_VDV
, 0, "DEVNO", "DEVNO",
209 &hp_setdev
, &hp_showdev
, &ptr_dev
},
214 "PTR", &ptr_unit
, ptr_reg
, ptr_mod
,
216 NULL
, NULL
, &ptr_reset
,
217 &ptr_boot
, &ptr_attach
, NULL
,
218 &ptr_dib
, DEV_DISABLE
221 /* PTP data structures
223 ptp_dev PTP device descriptor
224 ptp_unit PTP unit descriptor
225 ptp_mod PTP modifiers
226 ptp_reg PTP register list
229 DIB ptp_dib
= { PTP
, 0, 0, 0, 0, 0, &ptpio
};
232 UDATA (&ptp_svc
, UNIT_SEQ
+UNIT_ATTABLE
, 0), SERIAL_OUT_WAIT
236 { ORDATA (BUF
, ptp_unit
.buf
, 8) },
237 { FLDATA (CMD
, ptp_dib
.cmd
, 0) },
238 { FLDATA (CTL
, ptp_dib
.ctl
, 0) },
239 { FLDATA (FLG
, ptp_dib
.flg
, 0) },
240 { FLDATA (FBF
, ptp_dib
.fbf
, 0) },
241 { FLDATA (SRQ
, ptp_dib
.srq
, 0) },
242 { DRDATA (POS
, ptp_unit
.pos
, T_ADDR_W
), PV_LEFT
},
243 { DRDATA (TIME
, ptp_unit
.wait
, 24), PV_LEFT
},
244 { FLDATA (STOP_IOE
, ptp_stopioe
, 0) },
245 { ORDATA (DEVNO
, ptp_dib
.devno
, 6), REG_HRO
},
250 { MTAB_XTD
| MTAB_VDV
, 0, "DEVNO", "DEVNO",
251 &hp_setdev
, &hp_showdev
, &ptp_dev
},
256 "PTP", &ptp_unit
, ptp_reg
, ptp_mod
,
258 NULL
, NULL
, &ptp_reset
,
260 &ptp_dib
, DEV_DISABLE
263 /* TTY data structures
265 tty_dev TTY device descriptor
266 tty_unit TTY unit descriptor
267 tty_reg TTY register list
268 tty_mod TTy modifiers list
275 DIB tty_dib
= { TTY
, 0, 0, 0, 0, 0, &ttyio
};
278 { UDATA (&tti_svc
, UNIT_IDLE
| TT_MODE_UC
, 0), POLL_WAIT
},
279 { UDATA (&tto_svc
, TT_MODE_UC
, 0), TTY_OUT_WAIT
},
280 { UDATA (&tto_svc
, UNIT_SEQ
| UNIT_ATTABLE
| TT_MODE_8B
, 0), SERIAL_OUT_WAIT
}
284 { ORDATA (BUF
, tty_buf
, 8) },
285 { ORDATA (MODE
, tty_mode
, 16) },
286 { ORDATA (SHIN
, tty_shin
, 8), REG_HRO
},
287 { FLDATA (CMD
, tty_dib
.cmd
, 0), REG_HRO
},
288 { FLDATA (CTL
, tty_dib
.ctl
, 0) },
289 { FLDATA (FLG
, tty_dib
.flg
, 0) },
290 { FLDATA (FBF
, tty_dib
.fbf
, 0) },
291 { FLDATA (SRQ
, tty_dib
.srq
, 0) },
292 { FLDATA (KLFP
, tty_lf
, 0), REG_HRO
},
293 { DRDATA (KPOS
, tty_unit
[TTI
].pos
, T_ADDR_W
), PV_LEFT
},
294 { DRDATA (KTIME
, tty_unit
[TTI
].wait
, 24), REG_NZ
+ PV_LEFT
},
295 { DRDATA (TPOS
, tty_unit
[TTO
].pos
, T_ADDR_W
), PV_LEFT
},
296 { DRDATA (TTIME
, tty_unit
[TTO
].wait
, 24), REG_NZ
+ PV_LEFT
},
297 { DRDATA (PPOS
, tty_unit
[TTP
].pos
, T_ADDR_W
), PV_LEFT
},
298 { FLDATA (STOP_IOE
, ttp_stopioe
, 0) },
299 { ORDATA (DEVNO
, tty_dib
.devno
, 6), REG_HRO
},
304 { TT_MODE
, TT_MODE_UC
, "UC", "UC", &tty_set_opt
},
305 { TT_MODE
, TT_MODE_7B
, "7b", "7B", &tty_set_opt
},
306 { TT_MODE
, TT_MODE_8B
, "8b", "8B", &tty_set_opt
},
307 { TT_MODE
, TT_MODE_7P
, "7p", "7P", &tty_set_opt
},
308 { UNIT_AUTOLF
, UNIT_AUTOLF
, "autolf", "AUTOLF", &tty_set_alf
},
309 { UNIT_AUTOLF
, 0 , NULL
, "NOAUTOLF", &tty_set_alf
},
310 { MTAB_XTD
| MTAB_VDV
, 0, "DEVNO", "DEVNO",
311 &hp_setdev
, &hp_showdev
, &tty_dev
},
316 "TTY", tty_unit
, tty_reg
, tty_mod
,
318 NULL
, NULL
, &tty_reset
,
323 /* CLK data structures
325 clk_dev CLK device descriptor
326 clk_unit CLK unit descriptor
327 clk_mod CLK modifiers
328 clk_reg CLK register list
331 DIB clk_dib
= { CLK
, 0, 0, 0, 0, 0, &clkio
};
333 UNIT clk_unit
= { UDATA (&clk_svc
, UNIT_IDLE
, 0) };
336 { ORDATA (SEL
, clk_select
, 3) },
337 { DRDATA (CTR
, clk_ctr
, 14) },
338 { FLDATA (CMD
, clk_dib
.cmd
, 0), REG_HRO
},
339 { FLDATA (CTL
, clk_dib
.ctl
, 0) },
340 { FLDATA (FLG
, clk_dib
.flg
, 0) },
341 { FLDATA (FBF
, clk_dib
.fbf
, 0) },
342 { FLDATA (SRQ
, clk_dib
.srq
, 0) },
343 { FLDATA (ERR
, clk_error
, CLK_V_ERROR
) },
344 { BRDATA (TIME
, clk_time
, 10, 24, 8) },
345 { DRDATA (IPTICK
, clk_tick
, 24), PV_RSPC
| REG_RO
},
346 { ORDATA (DEVNO
, clk_dib
.devno
, 6), REG_HRO
},
351 { UNIT_DIAG
, UNIT_DIAG
, "diagnostic mode", "DIAG", NULL
},
352 { UNIT_DIAG
, 0, "calibrated", "CALIBRATED", NULL
},
353 { MTAB_XTD
| MTAB_VDV
, 0, "DEVNO", "DEVNO",
354 &hp_setdev
, &hp_showdev
, &clk_dev
},
359 "CLK", &clk_unit
, clk_reg
, clk_mod
,
361 NULL
, NULL
, &clk_reset
,
363 &clk_dib
, DEV_DISABLE
366 /* Paper tape reader IO instructions */
368 int32
ptrio (int32 inst
, int32 IR
, int32 dat
)
372 dev
= IR
& I_DEVMASK
; /* get device no */
373 switch (inst
) { /* case on opcode */
375 case ioFLG
: /* flag clear/set */
376 if ((IR
& I_HC
) == 0) { setFSR (dev
); } /* STF */
379 case ioSFC
: /* skip flag clear */
380 if (FLG (dev
) == 0) PC
= (PC
+ 1) & VAMASK
;
383 case ioSFS
: /* skip flag set */
384 if (FLG (dev
) != 0) PC
= (PC
+ 1) & VAMASK
;
387 case ioMIX
: /* merge */
388 dat
= dat
| ptr_unit
.buf
;
391 case ioLIX
: /* load */
395 case ioCRS
: /* control reset */
396 /* action same as CLC */
397 case ioCTL
: /* control clear/set */
398 if (IR
& I_CTL
) { /* CLC */
399 clrCMD (dev
); /* clear cmd, ctl */
403 setCMD (dev
); /* set cmd, ctl */
405 sim_activate (&ptr_unit
, ptr_unit
.wait
);
413 if (IR
& I_HC
) { clrFSR (dev
); } /* H/C option */
419 t_stat
ptr_svc (UNIT
*uptr
)
423 dev
= ptr_dib
.devno
; /* get device no */
424 clrCMD (dev
); /* clear cmd */
425 if ((ptr_unit
.flags
& UNIT_ATT
) == 0) /* attached? */
426 return IORETURN (ptr_stopioe
, SCPE_UNATT
);
427 while ((temp
= getc (ptr_unit
.fileref
)) == EOF
) { /* read byte, error? */
428 if (feof (ptr_unit
.fileref
)) { /* end of file? */
429 if ((ptr_unit
.flags
& UNIT_DIAG
) && (ptr_unit
.pos
> 0)) {
430 rewind (ptr_unit
.fileref
); /* rewind if loop mode */
434 if (ptr_trlcnt
>= ptr_trllim
) { /* added all trailer? */
435 if (ptr_stopioe
) { /* stop on error? */
436 printf ("PTR end of file\n");
439 else return SCPE_OK
; /* no, just hang */
441 ptr_trlcnt
++; /* count trailer */
442 temp
= 0; /* read a zero */
446 else { /* no, real error */
447 perror ("PTR I/O error");
448 clearerr (ptr_unit
.fileref
);
452 setFSR (dev
); /* set flag */
453 ptr_unit
.buf
= temp
& 0377; /* put byte in buf */
454 ptr_unit
.pos
= ftell (ptr_unit
.fileref
);
456 if (temp
) /* character non-null? */
457 ptr_trlcnt
= 0; /* clear trailing null counter */
462 /* Attach routine - clear the trailer counter */
464 t_stat
ptr_attach (UNIT
*uptr
, char *cptr
)
467 return attach_unit (uptr
, cptr
);
470 /* Reset routine - called from SCP, flags in DIB's */
472 t_stat
ptr_reset (DEVICE
*dptr
)
474 ptr_dib
.cmd
= ptr_dib
.ctl
= 0; /* clear cmd, ctl */
475 ptr_dib
.flg
= ptr_dib
.fbf
= ptr_dib
.srq
= 1; /* set flg, fbf, srq */
477 sim_cancel (&ptr_unit
); /* deactivate unit */
481 /* Paper tape reader bootstrap routine (HP 12992K ROM) */
483 const uint16 ptr_rom
[IBL_LNT
] = {
484 0107700, /*ST CLC 0,C ; intr off */
485 0002401, /* CLA,RSS ; skip in */
486 0063756, /*CN LDA M11 ; feed frame */
487 0006700, /* CLB,CCE ; set E to rd byte */
488 0017742, /* JSB READ ; get #char */
489 0007306, /* CMB,CCE,INB,SZB ; 2's comp */
490 0027713, /* JMP *+5 ; non-zero byte */
491 0002006, /* INA,SZA ; feed frame ctr */
492 0027703, /* JMP *-3 */
493 0102077, /* HLT 77B ; stop */
494 0027700, /* JMP ST ; next */
495 0077754, /* STA WC ; word in rec */
496 0017742, /* JSB READ ; get feed frame */
497 0017742, /* JSB READ ; get address */
498 0074000, /* STB 0 ; init csum */
499 0077755, /* STB AD ; save addr */
500 0067755, /*CK LDB AD ; check addr */
501 0047777, /* ADB MAXAD ; below loader */
502 0002040, /* SEZ ; E =0 => OK */
503 0027740, /* JMP H55 */
504 0017742, /* JSB READ ; get word */
505 0040001, /* ADA 1 ; cont checksum */
506 0177755, /* STA AD,I ; store word */
507 0037755, /* ISZ AD */
508 0000040, /* CLE ; force wd read */
509 0037754, /* ISZ WC ; block done? */
510 0027720, /* JMP CK ; no */
511 0017742, /* JSB READ ; get checksum */
512 0054000, /* CPB 0 ; ok? */
513 0027702, /* JMP CN ; next block */
514 0102011, /* HLT 11 ; bad csum */
515 0027700, /* JMP ST ; next */
516 0102055, /*H55 HALT 55 ; bad address */
517 0027700, /* JMP ST ; next */
519 0006600, /* CLB,CME ; E reg byte ptr */
520 0103710, /* STC RDR,C ; start reader */
521 0102310, /* SFS RDR ; wait */
522 0027745, /* JMP *-1 */
523 0106410, /* MIB RDR ; get byte */
524 0002041, /* SEZ,RSS ; E set? */
525 0127742, /* JMP RD,I ; no, done */
526 0005767, /* BLF,CLE,BLF ; shift byte */
527 0027744, /* JMP RD+2 ; again */
528 0000000, /*WC 000000 ; word count */
529 0000000, /*AD 000000 ; address */
530 0177765, /*M11 -11 ; feed count */
531 0, 0, 0, 0, 0, 0, 0, 0, /* unused */
532 0, 0, 0, 0, 0, 0, 0, /* unused */
533 0000000 /*MAXAD -ST ; max addr */
536 t_stat
ptr_boot (int32 unitno
, DEVICE
*dptr
)
540 dev
= ptr_dib
.devno
; /* get device no */
541 if (ibl_copy (ptr_rom
, dev
)) return SCPE_IERR
; /* copy boot to memory */
542 SR
= (SR
& IBL_OPT
) | IBL_PTR
| (dev
<< IBL_V_DEV
); /* set SR */
546 /* Paper tape punch IO instructions */
548 int32
ptpio (int32 inst
, int32 IR
, int32 dat
)
552 dev
= IR
& I_DEVMASK
; /* get device no */
553 switch (inst
) { /* case on opcode */
555 case ioFLG
: /* flag clear/set */
556 if ((IR
& I_HC
) == 0) { setFSR (dev
); } /* STF */
559 case ioSFC
: /* skip flag clear */
560 if (FLG (dev
) == 0) PC
= (PC
+ 1) & VAMASK
;
563 case ioSFS
: /* skip flag set */
564 if (FLG (dev
) != 0) PC
= (PC
+ 1) & VAMASK
;
567 case ioLIX
: /* load */
569 case ioMIX
: /* merge */
570 if ((ptp_unit
.flags
& UNIT_ATT
) == 0)
571 dat
= dat
| PTP_LOW
; /* out of tape? */
574 case ioOTX
: /* output */
578 case ioCRS
: /* control reset */
579 /* action same as CLC */
580 case ioCTL
: /* control clear/set */
581 if (IR
& I_CTL
) { /* CLC */
582 clrCMD (dev
); /* clear cmd, ctl */
586 setCMD (dev
); /* set cmd, ctl */
588 sim_activate (&ptp_unit
, ptp_unit
.wait
);
596 if (IR
& I_HC
) { clrFSR (dev
); } /* H/C option */
602 t_stat
ptp_svc (UNIT
*uptr
)
606 dev
= ptp_dib
.devno
; /* get device no */
607 clrCMD (dev
); /* clear cmd */
608 setFSR (dev
); /* set flag */
609 if ((ptp_unit
.flags
& UNIT_ATT
) == 0) /* attached? */
610 return IORETURN (ptp_stopioe
, SCPE_UNATT
);
611 if (putc (ptp_unit
.buf
, ptp_unit
.fileref
) == EOF
) { /* output byte */
612 perror ("PTP I/O error");
613 clearerr (ptp_unit
.fileref
);
616 ptp_unit
.pos
= ftell (ptp_unit
.fileref
); /* update position */
622 t_stat
ptp_reset (DEVICE
*dptr
)
624 ptp_dib
.cmd
= ptp_dib
.ctl
= 0; /* clear cmd, ctl */
625 ptp_dib
.flg
= ptp_dib
.fbf
= ptp_dib
.srq
= 1; /* set flg, fbf, srq */
627 sim_cancel (&ptp_unit
); /* deactivate unit */
631 /* Terminal IO instructions */
633 int32
ttyio (int32 inst
, int32 IR
, int32 dat
)
637 dev
= IR
& I_DEVMASK
; /* get device no */
638 switch (inst
) { /* case on opcode */
640 case ioFLG
: /* flag clear/set */
641 if ((IR
& I_HC
) == 0) { setFSR (dev
); } /* STF */
644 case ioSFC
: /* skip flag clear */
645 if (FLG (dev
) == 0) PC
= (PC
+ 1) & VAMASK
;
648 case ioSFS
: /* skip flag set */
649 if (FLG (dev
) != 0) PC
= (PC
+ 1) & VAMASK
;
652 case ioLIX
: /* load */
654 case ioMIX
: /* merge */
656 if (!(tty_mode
& TM_KBD
) && sim_is_active (&tty_unit
[TTO
]))
660 case ioOTX
: /* output */
661 if (dat
& TM_MODE
) tty_mode
= dat
& (TM_KBD
|TM_PRI
|TM_PUN
);
662 tty_buf
= dat
& 0377;
665 case ioCRS
: /* control reset */
666 clrCTL (dev
); /* clear control */
667 setFSR (dev
); /* set flag */
668 tty_mode
= TM_KBD
; /* set tty, clear print/punch */
669 tty_buf
= 0; /* clear buffer */
670 tty_shin
= 0377; /* input inactive */
671 tty_lf
= 0; /* no lf pending */
674 case ioCTL
: /* control clear/set */
675 if (IR
& I_CTL
) { clrCTL (dev
); } /* CLC */
678 if (!(tty_mode
& TM_KBD
)) /* output? */
679 sim_activate (&tty_unit
[TTO
], tty_unit
[TTO
].wait
);
687 if (IR
& I_HC
) { clrFSR (dev
); } /* H/C option */
691 /* TTY input service routine.
693 The console input poll routine is scheduled with a ten millisecond period
694 using a calibrated timer, which is the source of event timing for all of the
695 keyboard polling routines. Synchronizing other keyboard polls with the
696 console poll ensures maximum idle time.
698 Several HP operating systems require a CR and LF sequence for line
699 termination. This is awkward on a PC, as there is no LF key (CTRL+J is
700 needed instead). We provide an AUTOLF mode to add a LF automatically to each
701 CR input. When this mode is set, entering CR will set a flag, which will
702 cause a LF to be supplied automatically at the next input poll.
704 The 12531C teleprinter interface and the later 12880A CRT interface provide a
705 clever mechanism to detect a keypress during output. This is used by DOS and
706 RTE to allow the user to interrupt lengthy output operations to enter system
709 Referring to the 12531C schematic, the terminal input enters on pin X
710 ("DATA FROM EIA COMPATIBLE DEVICE"). The signal passes through four
711 transistor inversions (Q8, Q1, Q2, and Q3) to appear on pin 12 of NAND gate
712 U104C. If the flag flip-flop is not set, the terminal input passes to the
713 (inverted) output of U104C and thence to the D input of the first of the
714 flip-flops forming the data register.
716 In the idle condition (no key pressed), the terminal input line is marking
717 (voltage negative), so in passing through a total of five inversions, a
718 logic one is presented at the serial input of the data register. During an
719 output operation, the register is parallel loaded and serially shifted,
720 sending the output data through the register to the device and -- this is
721 the crux -- filling the register with logic ones from U104C.
723 At the end of the output operation, the card flag is set, an interrupt
724 occurs, and the RTE driver is entered. The driver then does an LIA SC to
725 read the contents of the data register. If no key has been pressed during
726 the output operation, the register will read as all ones (octal 377). If,
727 however, any key was struck, at least one zero bit will be present. If the
728 register value doesn't equal 377, the driver sets the system "operator
729 attention" flag, which will cause DOS or RTE to output an asterisk prompt and
730 initiate a terminal read when the current output line is completed.
733 t_stat
tti_svc (UNIT
*uptr
)
737 uptr
->wait
= sim_rtcn_calb (POLL_RATE
, TMR_POLL
); /* calibrate poll timer */
738 sim_activate (uptr
, uptr
->wait
); /* continue poll */
740 dev
= tty_dib
.devno
; /* get device no */
741 tty_shin
= 0377; /* assume inactive */
742 if (tty_lf
) { /* auto lf pending? */
743 c
= 012; /* force lf */
747 if ((c
= sim_poll_kbd ()) < SCPE_KFLAG
) return c
; /* no char or error? */
748 if (c
& SCPE_BREAK
) c
= 0; /* break? */
749 else c
= sim_tt_inpcvt (c
, TT_GET_MODE (uptr
->flags
));
750 tty_lf
= ((c
& 0177) == 015) && (uptr
->flags
& UNIT_AUTOLF
);
752 if (tty_mode
& TM_KBD
) { /* keyboard enabled? */
753 tty_buf
= c
; /* put char in buf */
754 uptr
->pos
= uptr
->pos
+ 1;
755 setFSR (dev
); /* set flag */
757 tto_out (c
); /* echo? */
758 return ttp_out (c
); /* punch? */
761 else tty_shin
= c
; /* no, char shifts in */
765 /* TTY output service routine */
767 t_stat
tto_svc (UNIT
*uptr
)
772 c
= tty_buf
; /* get char */
773 tty_buf
= tty_shin
; /* shift in */
774 tty_shin
= 0377; /* line inactive */
775 if ((r
= tto_out (c
)) != SCPE_OK
) { /* output; error? */
776 sim_activate (uptr
, uptr
->wait
); /* retry */
777 return ((r
== SCPE_STALL
)? SCPE_OK
: r
); /* !stall? report */
779 dev
= tty_dib
.devno
; /* get device no */
780 setFSR (dev
); /* set done flag */
781 return ttp_out (c
); /* punch if enabled */
784 t_stat
tto_out (int32 c
)
788 if (tty_mode
& TM_PRI
) { /* printing? */
789 c
= sim_tt_outcvt (c
, TT_GET_MODE (tty_unit
[TTO
].flags
));
790 if (c
>= 0) { /* valid? */
791 if (r
= sim_putchar_s (c
)) return r
; /* output char */
792 tty_unit
[TTO
].pos
= tty_unit
[TTO
].pos
+ 1;
798 t_stat
ttp_out (int32 c
)
800 if (tty_mode
& TM_PUN
) { /* punching? */
801 if ((tty_unit
[TTP
].flags
& UNIT_ATT
) == 0) /* attached? */
802 return IORETURN (ttp_stopioe
, SCPE_UNATT
);
803 if (putc (c
, tty_unit
[TTP
].fileref
) == EOF
) { /* output char */
804 perror ("TTP I/O error");
805 clearerr (tty_unit
[TTP
].fileref
);
808 tty_unit
[TTP
].pos
= ftell (tty_unit
[TTP
].fileref
);
813 /* TTY reset routine */
815 t_stat
tty_reset (DEVICE
*dptr
)
817 tty_dib
.cmd
= tty_dib
.ctl
= 0; /* clear cmd, ctl */
818 tty_dib
.flg
= tty_dib
.fbf
= tty_dib
.srq
= 1; /* set flg, fbf, srq */
819 tty_mode
= TM_KBD
; /* enable input */
821 tty_shin
= 0377; /* input inactive */
822 tty_lf
= 0; /* no lf pending */
823 tty_unit
[TTI
].wait
= POLL_WAIT
; /* reset initial poll */
824 sim_rtcn_init (tty_unit
[TTI
].wait
, TMR_POLL
); /* init poll timer */
825 sim_activate (&tty_unit
[TTI
], tty_unit
[TTI
].wait
); /* activate poll */
826 sim_cancel (&tty_unit
[TTO
]); /* cancel output */
830 t_stat
tty_set_opt (UNIT
*uptr
, int32 val
, char *cptr
, void *desc
)
832 int32 u
= uptr
- tty_dev
.units
;
834 if (u
> TTO
) return SCPE_NOFNC
;
835 if ((u
== TTI
) && (val
== TT_MODE_7P
))
837 tty_unit
[u
].flags
= (tty_unit
[u
].flags
& ~TT_MODE
) | val
;
841 t_stat
tty_set_alf (UNIT
*uptr
, int32 val
, char *cptr
, void *desc
)
843 int32 u
= uptr
- tty_dev
.units
;
845 if (u
!= TTI
) return SCPE_NOFNC
;
849 /* Synchronize polling.
851 Return an event time corresponding either with the amount of time remaining
852 in the current poll (mode = INITIAL) or the amount of time in a full poll
853 period (mode = SERVICE). If the former call is made when the device service
854 routine is started, then making the latter call during unit service will
855 ensure that the polls remain synchronized.
858 int32
sync_poll (POLLMODE poll_mode
)
862 if (poll_mode
== INITIAL
) {
863 poll_time
= sim_is_active (&tty_unit
[TTI
]);
871 return tty_unit
[TTI
].wait
;
875 /* Clock I/O instructions.
877 The time base generator (CLK) provides periodic interrupts from 100
878 microseconds to 1000 seconds. The CLK uses a calibrated timer to provide the
879 time base. For periods ranging from 1 to 1000 seconds, a 100 millisecond
880 timer is used, and 10 to 10000 ticks are counted before setting the device
881 flag to indicate that the period has expired.
883 If the period is set to ten milliseconds, the console poll timer is used
884 instead of an independent timer. This is to maximize the idle period.
886 In diagnostic mode, the clock period is set to the expected number of CPU
887 instructions, rather than wall-clock time, so that the diagnostic executes as
891 int32
clkio (int32 inst
, int32 IR
, int32 dat
)
895 dev
= IR
& I_DEVMASK
; /* get device no */
896 switch (inst
) { /* case on opcode */
898 case ioFLG
: /* flag clear/set */
899 if ((IR
& I_HC
) == 0) { setFSR (dev
); } /* STF */
902 case ioSFC
: /* skip flag clear */
903 if (FLG (dev
) == 0) PC
= (PC
+ 1) & VAMASK
;
906 case ioSFS
: /* skip flag set */
907 if (FLG (dev
) != 0) PC
= (PC
+ 1) & VAMASK
;
910 case ioMIX
: /* merge */
911 dat
= dat
| clk_error
;
914 case ioLIX
: /* load */
918 case ioOTX
: /* output */
919 clk_select
= dat
& 07; /* save select */
920 sim_cancel (&clk_unit
); /* stop the clock */
921 clrCTL (dev
); /* clear control */
924 case ioCRS
: /* control reset */
925 /* action same as CLC */
926 case ioCTL
: /* control clear/set */
927 if (IR
& I_CTL
) { /* CLC */
928 clrCTL (dev
); /* turn off clock */
929 sim_cancel (&clk_unit
); /* deactivate unit */
932 setCTL (dev
); /* set CTL */
934 if (clk_unit
.flags
& UNIT_DIAG
) /* diag mode? */
935 clk_unit
.flags
= clk_unit
.flags
& ~UNIT_IDLE
; /* not calibrated */
937 clk_unit
.flags
= clk_unit
.flags
| UNIT_IDLE
; /* is calibrated */
939 if (!sim_is_active (&clk_unit
)) { /* clock running? */
940 clk_tick
= clk_delay (0); /* get tick count */
942 if ((clk_unit
.flags
& UNIT_DIAG
) == 0) /* calibrated? */
943 if (clk_select
== 2) /* 10 msec. interval? */
944 clk_tick
= sync_poll (INITIAL
); /* sync poll */
946 sim_rtcn_init (clk_tick
, TMR_CLK
); /* initialize timer */
948 sim_activate (&clk_unit
, clk_tick
); /* start clock */
949 clk_ctr
= clk_delay (1); /* set repeat ctr */
951 clk_error
= 0; /* clear error */
959 if (IR
& I_HC
) { clrFSR (dev
); } /* H/C option */
965 As with the I/O handler, if the time base period is set to ten milliseconds,
966 the console poll timer is used instead of an independent timer.
969 t_stat
clk_svc (UNIT
*uptr
)
973 dev
= clk_dib
.devno
; /* get device no */
974 if (!CTL (dev
)) return SCPE_OK
; /* CTL off? done */
976 if (clk_unit
.flags
& UNIT_DIAG
) /* diag mode? */
977 clk_tick
= clk_delay (0); /* get fixed delay */
978 else if (clk_select
== 2) /* 10 msec period? */
979 clk_tick
= sync_poll (SERVICE
); /* sync poll */
981 clk_tick
= sim_rtcn_calb (clk_tps
[clk_select
], TMR_CLK
); /* calibrate delay */
983 sim_activate (uptr
, clk_tick
); /* reactivate */
984 clk_ctr
= clk_ctr
- 1; /* decrement counter */
985 if (clk_ctr
<= 0) { /* end of interval? */
986 if (FLG (dev
)) clk_error
= CLK_ERROR
; /* overrun? error */
987 else { setFSR (dev
); } /* else set flag */
988 clk_ctr
= clk_delay (1); /* reset counter */
995 t_stat
clk_reset (DEVICE
*dptr
)
997 clk_dib
.cmd
= clk_dib
.ctl
= 0; /* clear cmd, ctl */
998 clk_dib
.flg
= clk_dib
.fbf
= clk_dib
.srq
= 1; /* set flg, fbf, srq */
999 clk_error
= 0; /* clear error */
1000 clk_select
= 0; /* clear select */
1001 clk_ctr
= 0; /* clear counter */
1002 sim_cancel (&clk_unit
); /* deactivate unit */
1006 /* Clock delay routine */
1008 int32
clk_delay (int32 flg
)
1010 int32 sel
= clk_select
;
1012 if ((clk_unit
.flags
& UNIT_DIAG
) && (sel
>= 4)) sel
= sel
- 3;
1013 if (flg
) return clk_rpt
[sel
];
1014 else return clk_time
[sel
];