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