Commit | Line | Data |
---|---|---|
196ba1fc PH |
1 | /* i1401_lp.c: IBM 1403 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 1403 line printer\r | |
27 | \r | |
28 | 19-Jan-07 RMS Added UNIT_TEXT flag\r | |
29 | 07-Mar-05 RMS Fixed bug in write_line (reported by Van Snyder)\r | |
30 | 25-Apr-03 RMS Revised for extended file support\r | |
31 | 30-May-02 RMS Widened POS to 32b\r | |
32 | 13-Apr-01 RMS Revised for register arrays\r | |
33 | */\r | |
34 | \r | |
35 | #include "i1401_defs.h"\r | |
36 | \r | |
37 | extern uint8 M[];\r | |
38 | extern char bcd_to_ascii_old[64];\r | |
39 | extern char bcd_to_ascii_a[64], bcd_to_ascii_h[64];\r | |
40 | extern char bcd_to_pca[64], bcd_to_pch[64];\r | |
41 | extern int32 iochk, ind[64];\r | |
42 | extern t_bool conv_old;\r | |
43 | \r | |
44 | int32 cct[CCT_LNT] = { 03 };\r | |
45 | int32 cctlnt = 66, cctptr = 0, lines = 0, lflag = 0;\r | |
46 | \r | |
47 | t_stat lpt_reset (DEVICE *dptr);\r | |
48 | t_stat lpt_attach (UNIT *uptr, char *cptr);\r | |
49 | t_stat space (int32 lines, int32 lflag);\r | |
50 | \r | |
51 | char *pch_table_old[4] = {\r | |
52 | bcd_to_ascii_old, bcd_to_pca, bcd_to_pch, bcd_to_ascii_old\r | |
53 | };\r | |
54 | char *pch_table[4] = {\r | |
55 | bcd_to_ascii_a, bcd_to_pca, bcd_to_pch, bcd_to_ascii_h\r | |
56 | };\r | |
57 | \r | |
58 | #define UNIT_V_FT (UNIT_V_UF + 0)\r | |
59 | #define UNIT_V_48 (UNIT_V_UF + 1)\r | |
60 | #define UNIT_FT (1 << UNIT_V_FT)\r | |
61 | #define UNIT_48 (1 << UNIT_V_48)\r | |
62 | #define GET_PCHAIN(x) (((x) >> UNIT_V_FT) & (UNIT_FT|UNIT_48))\r | |
63 | #define CHP(ch,val) ((val) & (1 << (ch)))\r | |
64 | \r | |
65 | /* LPT data structures\r | |
66 | \r | |
67 | lpt_dev LPT device descriptor\r | |
68 | lpt_unit LPT unit descriptor\r | |
69 | lpt_reg LPT register list\r | |
70 | */\r | |
71 | \r | |
72 | UNIT lpt_unit = {\r | |
73 | UDATA (NULL, UNIT_SEQ+UNIT_ATTABLE+UNIT_TEXT, 0)\r | |
74 | };\r | |
75 | \r | |
76 | REG lpt_reg[] = {\r | |
77 | { FLDATA (ERR, ind[IN_LPT], 0) },\r | |
78 | { DRDATA (POS, lpt_unit.pos, T_ADDR_W), PV_LEFT },\r | |
79 | { BRDATA (CCT, cct, 8, 32, CCT_LNT) },\r | |
80 | { DRDATA (LINES, lines, 8), PV_LEFT },\r | |
81 | { DRDATA (CCTP, cctptr, 8), PV_LEFT },\r | |
82 | { DRDATA (CCTL, cctlnt, 8), REG_RO + PV_LEFT },\r | |
83 | { NULL }\r | |
84 | };\r | |
85 | \r | |
86 | MTAB lpt_mod[] = {\r | |
87 | { UNIT_48, UNIT_48, "48 character chain", "48" },\r | |
88 | { UNIT_48, 0, "64 character chain", "64" },\r | |
89 | { UNIT_FT, UNIT_FT, "Fortran set", "FORTRAN" },\r | |
90 | { UNIT_FT, 0, "business set", "BUSINESS" },\r | |
91 | { UNIT_FT|UNIT_48, 0, NULL, "PCF" }, /* obsolete */\r | |
92 | { UNIT_FT|UNIT_48, UNIT_48, NULL, "PCA" },\r | |
93 | { UNIT_FT|UNIT_48, UNIT_FT|UNIT_48, NULL, "PCH" },\r | |
94 | { 0 }\r | |
95 | };\r | |
96 | \r | |
97 | DEVICE lpt_dev = {\r | |
98 | "LPT", &lpt_unit, lpt_reg, lpt_mod,\r | |
99 | 1, 10, 31, 1, 8, 7,\r | |
100 | NULL, NULL, &lpt_reset,\r | |
101 | NULL, &lpt_attach, NULL\r | |
102 | };\r | |
103 | \r | |
104 | /* Print routine\r | |
105 | \r | |
106 | Modifiers have been checked by the caller\r | |
107 | SQUARE = word mark mode\r | |
108 | S = suppress automatic newline\r | |
109 | */\r | |
110 | \r | |
111 | t_stat write_line (int32 ilnt, int32 mod)\r | |
112 | {\r | |
113 | int32 i, t, wm, sup;\r | |
114 | char *bcd2asc;\r | |
115 | static char lbuf[LPT_WIDTH + 1]; /* + null */\r | |
116 | \r | |
117 | if ((lpt_unit.flags & UNIT_ATT) == 0) return SCPE_UNATT; /* attached? */\r | |
118 | wm = ((ilnt == 2) || (ilnt == 5)) && (mod == BCD_SQUARE);\r | |
119 | sup = ((ilnt == 2) || (ilnt == 5)) && (mod == BCD_S);\r | |
120 | ind[IN_LPT] = 0; /* clear error */\r | |
121 | if (conv_old) /* get print chain */\r | |
122 | bcd2asc = pch_table_old[GET_PCHAIN (lpt_unit.flags)];\r | |
123 | else bcd2asc = pch_table[GET_PCHAIN (lpt_unit.flags)];\r | |
124 | for (i = 0; i < LPT_WIDTH; i++) { /* convert print buf */\r | |
125 | t = M[LPT_BUF + i];\r | |
126 | if (wm) lbuf[i] = (t & WM)? '1': ' '; /* wmarks -> 1 or sp */\r | |
127 | else lbuf[i] = bcd2asc[t & CHAR]; /* normal */\r | |
128 | }\r | |
129 | lbuf[LPT_WIDTH] = 0; /* trailing null */\r | |
130 | for (i = LPT_WIDTH - 1; (i >= 0) && (lbuf[i] == ' '); i--) lbuf[i] = 0;\r | |
131 | fputs (lbuf, lpt_unit.fileref); /* write line */\r | |
132 | if (lines) space (lines, lflag); /* cc action? do it */\r | |
133 | else if (sup == 0) space (1, FALSE); /* default? 1 line */\r | |
134 | else {\r | |
135 | fputc ('\r', lpt_unit.fileref); /* sup -> overprint */\r | |
136 | lpt_unit.pos = ftell (lpt_unit.fileref); /* update position */\r | |
137 | }\r | |
138 | lines = lflag = 0; /* clear cc action */\r | |
139 | if (ferror (lpt_unit.fileref)) { /* error? */\r | |
140 | ind[IN_LPT] = 1;\r | |
141 | perror ("Line printer I/O error");\r | |
142 | clearerr (lpt_unit.fileref);\r | |
143 | if (iochk) return SCPE_IOERR;\r | |
144 | }\r | |
145 | return SCPE_OK;\r | |
146 | }\r | |
147 | \r | |
148 | /* Carriage control routine\r | |
149 | \r | |
150 | The modifier has not been checked, its format is\r | |
151 | <5:4> = 00, skip to channel now\r | |
152 | = 01, space lines after\r | |
153 | = 10, space lines now\r | |
154 | = 11, skip to channel after\r | |
155 | <3:0> = number of lines or channel number\r | |
156 | */\r | |
157 | \r | |
158 | t_stat carriage_control (int32 mod)\r | |
159 | {\r | |
160 | int32 i, action;\r | |
161 | \r | |
162 | action = (mod & ZONE) >> V_ZONE; /* get mod type */\r | |
163 | mod = mod & DIGIT; /* isolate value */\r | |
164 | \r | |
165 | switch (action) {\r | |
166 | \r | |
167 | case 0: /* to channel now */\r | |
168 | if ((mod == 0) || (mod > 12) || CHP (mod, cct[cctptr])) return SCPE_OK;\r | |
169 | for (i = 1; i < cctlnt + 1; i++) { /* sweep thru cct */\r | |
170 | if (CHP (mod, cct[(cctptr + i) % cctlnt]))\r | |
171 | return space (i, TRUE);\r | |
172 | }\r | |
173 | return STOP_CCT; /* runaway channel */\r | |
174 | \r | |
175 | case 1: /* space after */\r | |
176 | if (mod <= 3) {\r | |
177 | lines = mod; /* save # lines */\r | |
178 | lflag = FALSE; /* flag spacing */\r | |
179 | ind[IN_CC9] = ind[IN_CC12] = 0;\r | |
180 | }\r | |
181 | return SCPE_OK;\r | |
182 | \r | |
183 | case 2: /* space now */\r | |
184 | if (mod <= 3) return space (mod, FALSE);\r | |
185 | return SCPE_OK;\r | |
186 | \r | |
187 | case 3: /* to channel after */\r | |
188 | if ((mod == 0) || (mod > 12)) return SCPE_OK; /* check channel */\r | |
189 | ind[IN_CC9] = ind[IN_CC12] = 0;\r | |
190 | for (i = 1; i < cctlnt + 1; i++) { /* sweep thru cct */\r | |
191 | if (CHP (mod, cct[(cctptr + i) % cctlnt])) {\r | |
192 | lines = i; /* save # lines */\r | |
193 | lflag = TRUE; /* flag skipping */\r | |
194 | return SCPE_OK;\r | |
195 | }\r | |
196 | }\r | |
197 | return STOP_CCT; /* runaway channel */\r | |
198 | }\r | |
199 | \r | |
200 | return SCPE_OK;\r | |
201 | }\r | |
202 | \r | |
203 | /* Space routine - space or skip n lines\r | |
204 | \r | |
205 | Inputs:\r | |
206 | count = number of lines to space or skip\r | |
207 | sflag = skip (TRUE) or space (FALSE)\r | |
208 | */\r | |
209 | \r | |
210 | t_stat space (int32 count, int32 sflag)\r | |
211 | {\r | |
212 | int32 i;\r | |
213 | \r | |
214 | if ((lpt_unit.flags & UNIT_ATT) == 0) return SCPE_UNATT;\r | |
215 | cctptr = (cctptr + count) % cctlnt; /* adv cct, mod lnt */\r | |
216 | if (sflag && CHP (0, cct[cctptr])) /* skip, top of form? */\r | |
217 | fputs ("\n\f", lpt_unit.fileref); /* nl, ff */\r | |
218 | else {\r | |
219 | for (i = 0; i < count; i++) fputc ('\n', lpt_unit.fileref);\r | |
220 | }\r | |
221 | lpt_unit.pos = ftell (lpt_unit.fileref); /* update position */\r | |
222 | ind[IN_CC9] = CHP (9, cct[cctptr]) != 0; /* set indicators */\r | |
223 | ind[IN_CC12] = CHP (12, cct[cctptr]) != 0;\r | |
224 | return SCPE_OK;\r | |
225 | }\r | |
226 | \r | |
227 | /* Reset routine */\r | |
228 | \r | |
229 | t_stat lpt_reset (DEVICE *dptr)\r | |
230 | {\r | |
231 | cctptr = 0; /* clear cct ptr */\r | |
232 | lines = lflag = 0; /* no cc action */\r | |
233 | ind[IN_LPT] = 0;\r | |
234 | return SCPE_OK;\r | |
235 | }\r | |
236 | \r | |
237 | /* Attach routine */\r | |
238 | \r | |
239 | t_stat lpt_attach (UNIT *uptr, char *cptr)\r | |
240 | {\r | |
241 | cctptr = 0; /* clear cct ptr */\r | |
242 | lines = 0; /* no cc action */\r | |
243 | ind[IN_LPT] = 0;\r | |
244 | return attach_unit (uptr, cptr);\r | |
245 | }\r |