First Commit of my working state
[simh.git] / PDP8 / pdp8_lp.c
1 /* pdp8_lp.c: PDP-8 line printer simulator
2
3 Copyright (c) 1993-2007, 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 LP8E line printer
27
28 19-Jan-07 RMS Added UNIT_TEXT
29 25-Apr-03 RMS Revised for extended file support
30 04-Oct-02 RMS Added DIB, enable/disable, device number support
31 30-May-02 RMS Widened POS to 32b
32 */
33
34 #include "pdp8_defs.h"
35
36 extern int32 int_req, int_enable, dev_done, stop_inst;
37
38 int32 lpt_err = 0; /* error flag */
39 int32 lpt_stopioe = 0; /* stop on error */
40
41 DEVICE lpt_dev;
42 int32 lpt (int32 IR, int32 AC);
43 t_stat lpt_svc (UNIT *uptr);
44 t_stat lpt_reset (DEVICE *dptr);
45 t_stat lpt_attach (UNIT *uptr, char *cptr);
46 t_stat lpt_detach (UNIT *uptr);
47
48 /* LPT data structures
49
50 lpt_dev LPT device descriptor
51 lpt_unit LPT unit descriptor
52 lpt_reg LPT register list
53 */
54
55 DIB lpt_dib = { DEV_LPT, 1, { &lpt } };
56
57 UNIT lpt_unit = {
58 UDATA (&lpt_svc, UNIT_SEQ+UNIT_ATTABLE+UNIT_TEXT, 0), SERIAL_OUT_WAIT
59 };
60
61 REG lpt_reg[] = {
62 { ORDATA (BUF, lpt_unit.buf, 8) },
63 { FLDATA (ERR, lpt_err, 0) },
64 { FLDATA (DONE, dev_done, INT_V_LPT) },
65 { FLDATA (ENABLE, int_enable, INT_V_LPT) },
66 { FLDATA (INT, int_req, INT_V_LPT) },
67 { DRDATA (POS, lpt_unit.pos, T_ADDR_W), PV_LEFT },
68 { DRDATA (TIME, lpt_unit.wait, 24), PV_LEFT },
69 { FLDATA (STOP_IOE, lpt_stopioe, 0) },
70 { ORDATA (DEVNUM, lpt_dib.dev, 6), REG_HRO },
71 { NULL }
72 };
73
74 MTAB lpt_mod[] = {
75 { MTAB_XTD|MTAB_VDV, 0, "DEVNO", "DEVNO",
76 &set_dev, &show_dev, NULL },
77 { 0 }
78 };
79
80 DEVICE lpt_dev = {
81 "LPT", &lpt_unit, lpt_reg, lpt_mod,
82 1, 10, 31, 1, 8, 8,
83 NULL, NULL, &lpt_reset,
84 NULL, &lpt_attach, &lpt_detach,
85 &lpt_dib, DEV_DISABLE
86 };
87
88 /* IOT routine */
89
90 int32 lpt (int32 IR, int32 AC)
91 {
92 switch (IR & 07) { /* decode IR<9:11> */
93
94 case 1: /* PSKF */
95 return (dev_done & INT_LPT)? IOT_SKP + AC: AC;
96
97 case 2: /* PCLF */
98 dev_done = dev_done & ~INT_LPT; /* clear flag */
99 int_req = int_req & ~INT_LPT; /* clear int req */
100 return AC;
101
102 case 3: /* PSKE */
103 return (lpt_err)? IOT_SKP + AC: AC;
104
105 case 6: /* PCLF!PSTB */
106 dev_done = dev_done & ~INT_LPT; /* clear flag */
107 int_req = int_req & ~INT_LPT; /* clear int req */
108
109 case 4: /* PSTB */
110 lpt_unit.buf = AC & 0177; /* load buffer */
111 if ((lpt_unit.buf == 015) || (lpt_unit.buf == 014) ||
112 (lpt_unit.buf == 012)) {
113 sim_activate (&lpt_unit, lpt_unit.wait);
114 return AC;
115 }
116 return (lpt_svc (&lpt_unit) << IOT_V_REASON) + AC;
117
118 case 5: /* PSIE */
119 int_enable = int_enable | INT_LPT; /* set enable */
120 int_req = INT_UPDATE; /* update interrupts */
121 return AC;
122
123 case 7: /* PCIE */
124 int_enable = int_enable & ~INT_LPT; /* clear enable */
125 int_req = int_req & ~INT_LPT; /* clear int req */
126 return AC;
127
128 default:
129 return (stop_inst << IOT_V_REASON) + AC;
130 } /* end switch */
131 }
132
133 /* Unit service */
134
135 t_stat lpt_svc (UNIT *uptr)
136 {
137 dev_done = dev_done | INT_LPT; /* set done */
138 int_req = INT_UPDATE; /* update interrupts */
139 if ((uptr->flags & UNIT_ATT) == 0) {
140 lpt_err = 1;
141 return IORETURN (lpt_stopioe, SCPE_UNATT);
142 }
143 fputc (uptr->buf, uptr->fileref); /* print char */
144 uptr->pos = ftell (uptr->fileref);
145 if (ferror (uptr->fileref)) { /* error? */
146 perror ("LPT I/O error");
147 clearerr (uptr->fileref);
148 return SCPE_IOERR;
149 }
150 return SCPE_OK;
151 }
152
153 /* Reset routine */
154
155 t_stat lpt_reset (DEVICE *dptr)
156 {
157 lpt_unit.buf = 0;
158 dev_done = dev_done & ~INT_LPT; /* clear done, int */
159 int_req = int_req & ~INT_LPT;
160 int_enable = int_enable | INT_LPT; /* set enable */
161 lpt_err = (lpt_unit.flags & UNIT_ATT) == 0;
162 sim_cancel (&lpt_unit); /* deactivate unit */
163 return SCPE_OK;
164 }
165
166 /* Attach routine */
167
168 t_stat lpt_attach (UNIT *uptr, char *cptr)
169 {
170 t_stat reason;
171
172 reason = attach_unit (uptr, cptr);
173 lpt_err = (lpt_unit.flags & UNIT_ATT) == 0;
174 return reason;
175 }
176
177 /* Detach routine */
178
179 t_stat lpt_detach (UNIT *uptr)
180 {
181 lpt_err = 1;
182 return detach_unit (uptr);
183 }