First Commit of my working state
[simh.git] / NOVA / nova_lp.c
1 /* nova_lp.c: NOVA line printer simulator
2
3 Copyright (c) 1993-2008, 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 lpt line printer
27
28 04-Jul-07 BKR DEV_SET/CLR macros now used,
29 <FF>, <CR>, <LF> output character delay now contingent upon non-zero TIME value,
30 LPT can now be DISABLED
31 19-Jan-07 RMS Added UNIT_TEXT
32 25-Apr-03 RMS Revised for extended file support
33 30-May-02 RMS Widened POS to 32b
34
35
36 Notes:
37 - data currently masked to 7 bits.
38 - if register TIME is non-zero, then delay TIME events if <FF>, <CR> or <LF> seen
39 - register POS show the current file position
40 - register STOP_IOE determines return value issued if output to unattached LPT is attempted
41 */
42
43 #include "nova_defs.h"
44
45 extern int32 int_req, dev_busy, dev_done, dev_disable;
46
47
48 int32 lpt_stopioe = 0; /* stop on error flag */
49
50 int32 lpt (int32 pulse, int32 code, int32 AC);
51 t_stat lpt_svc (UNIT *uptr);
52 t_stat lpt_reset (DEVICE *dptr);
53
54 /* LPT data structures
55
56 lpt_dev LPT device descriptor
57 lpt_unit LPT unit descriptor
58 lpt_reg LPT register list
59 */
60
61 DIB lpt_dib = { DEV_LPT, INT_LPT, PI_LPT, &lpt };
62
63 UNIT lpt_unit = { /* 2007-May-30, bkr */
64 UDATA (&lpt_svc, UNIT_SEQ+UNIT_ATTABLE+UNIT_TEXT, 0), SERIAL_OUT_WAIT
65 };
66
67 REG lpt_reg[] = {
68 { ORDATA (BUF, lpt_unit.buf, 8) },
69 { FLDATA (BUSY, dev_busy, INT_V_LPT) },
70 { FLDATA (DONE, dev_done, INT_V_LPT) },
71 { FLDATA (DISABLE, dev_disable, INT_V_LPT) },
72 { FLDATA (INT, int_req, INT_V_LPT) },
73 { DRDATA (POS, lpt_unit.pos, T_ADDR_W), PV_LEFT },
74 { DRDATA (TIME, lpt_unit.wait, 24), PV_LEFT },
75 { FLDATA (STOP_IOE, lpt_stopioe, 0) },
76 { NULL }
77 };
78
79 DEVICE lpt_dev = {
80 "LPT", &lpt_unit, lpt_reg, NULL,
81 1, 10, 31, 1, 8, 8,
82 NULL, NULL, &lpt_reset,
83 NULL, NULL, NULL,
84 &lpt_dib, DEV_DISABLE
85 };
86
87
88 /* IOT routine */
89
90 int32 lpt (int32 pulse, int32 code, int32 AC)
91 {
92 if (code == ioDOA)
93 lpt_unit.buf = AC & 0177 ;
94
95 switch (pulse)
96 { /* decode IR<8:9> */
97 case iopS: /* start */
98 DEV_SET_BUSY( INT_LPT ) ;
99 DEV_CLR_DONE( INT_LPT ) ;
100 DEV_UPDATE_INTR ;
101 if ( lpt_unit.wait )
102 if ( (lpt_unit.buf == 015)
103 || (lpt_unit.buf == 014)
104 || (lpt_unit.buf == 012)
105 )
106 {
107 sim_activate (&lpt_unit, lpt_unit.wait);
108 break ;
109 }
110 return (lpt_svc (&lpt_unit) << IOT_V_REASON);
111 break;
112
113 case iopC: /* clear */
114 DEV_CLR_BUSY( INT_LPT ) ;
115 DEV_CLR_DONE( INT_LPT ) ;
116 DEV_UPDATE_INTR ;
117 sim_cancel (&lpt_unit); /* deactivate unit */
118 break;
119 } /* end switch */
120
121 return 0;
122 }
123
124
125 /* Unit service */
126
127 t_stat lpt_svc (UNIT *uptr)
128 {
129 DEV_CLR_BUSY( INT_LPT ) ;
130 DEV_SET_DONE( INT_LPT ) ;
131 DEV_UPDATE_INTR ;
132 if ((lpt_unit.flags & UNIT_ATT) == 0) /* attached? */
133 return IORETURN (lpt_stopioe, SCPE_UNATT);
134 fputc (uptr->buf, uptr->fileref);
135 uptr->pos = ftell (uptr->fileref);
136 if (ferror (uptr->fileref)) {
137 perror ("LPT I/O error");
138 clearerr (uptr->fileref);
139 return SCPE_IOERR;
140 }
141 return SCPE_OK;
142 }
143
144
145 /* Reset routine */
146
147 t_stat lpt_reset (DEVICE *dptr)
148 {
149 lpt_unit.buf = 0; /* (not DG compatible) */
150 DEV_CLR_BUSY( INT_LPT ) ;
151 DEV_CLR_DONE( INT_LPT ) ;
152 DEV_UPDATE_INTR ;
153 sim_cancel (&lpt_unit); /* deactivate unit */
154 return SCPE_OK;
155 }