28f792f4eeab2931e51af58edc7f436d34841f68
1 /* pdp8_lp.c: PDP-8 line printer simulator
3 Copyright (c) 1993-2007, 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.
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
34 #include "pdp8_defs.h"
36 extern int32 int_req
, int_enable
, dev_done
, stop_inst
;
38 int32 lpt_err
= 0; /* error flag */
39 int32 lpt_stopioe
= 0; /* stop on error */
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
);
48 /* LPT data structures
50 lpt_dev LPT device descriptor
51 lpt_unit LPT unit descriptor
52 lpt_reg LPT register list
55 DIB lpt_dib
= { DEV_LPT
, 1, { &lpt
} };
58 UDATA (&lpt_svc
, UNIT_SEQ
+UNIT_ATTABLE
+UNIT_TEXT
, 0), SERIAL_OUT_WAIT
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
},
75 { MTAB_XTD
|MTAB_VDV
, 0, "DEVNO", "DEVNO",
76 &set_dev
, &show_dev
, NULL
},
81 "LPT", &lpt_unit
, lpt_reg
, lpt_mod
,
83 NULL
, NULL
, &lpt_reset
,
84 NULL
, &lpt_attach
, &lpt_detach
,
90 int32
lpt (int32 IR
, int32 AC
)
92 switch (IR
& 07) { /* decode IR<9:11> */
95 return (dev_done
& INT_LPT
)? IOT_SKP
+ AC
: AC
;
98 dev_done
= dev_done
& ~INT_LPT
; /* clear flag */
99 int_req
= int_req
& ~INT_LPT
; /* clear int req */
103 return (lpt_err
)? IOT_SKP
+ AC
: AC
;
105 case 6: /* PCLF!PSTB */
106 dev_done
= dev_done
& ~INT_LPT
; /* clear flag */
107 int_req
= int_req
& ~INT_LPT
; /* clear int req */
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
);
116 return (lpt_svc (&lpt_unit
) << IOT_V_REASON
) + AC
;
119 int_enable
= int_enable
| INT_LPT
; /* set enable */
120 int_req
= INT_UPDATE
; /* update interrupts */
124 int_enable
= int_enable
& ~INT_LPT
; /* clear enable */
125 int_req
= int_req
& ~INT_LPT
; /* clear int req */
129 return (stop_inst
<< IOT_V_REASON
) + AC
;
135 t_stat
lpt_svc (UNIT
*uptr
)
137 dev_done
= dev_done
| INT_LPT
; /* set done */
138 int_req
= INT_UPDATE
; /* update interrupts */
139 if ((uptr
->flags
& UNIT_ATT
) == 0) {
141 return IORETURN (lpt_stopioe
, SCPE_UNATT
);
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
);
155 t_stat
lpt_reset (DEVICE
*dptr
)
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 */
168 t_stat
lpt_attach (UNIT
*uptr
, char *cptr
)
172 reason
= attach_unit (uptr
, cptr
);
173 lpt_err
= (lpt_unit
.flags
& UNIT_ATT
) == 0;
179 t_stat
lpt_detach (UNIT
*uptr
)
182 return detach_unit (uptr
);