1 /* ibm1130_prt.c: IBM 1130 line printer emulation
3 Based on the SIMH simulator package written by Robert M Supnik
8 2006.12.06 - Moved CGI stuff out of this routine into cgi1130 main() module.
10 2006.07.06 - Made 1403 printer 132 columns wide, was 120 previously
12 2006.01.03 - Fixed bug in prt_attach, found and fixed by Carl Claunch. Detach followed
13 by reattach of 1403-mode printer left device permanently not-ready.
15 2004.11.08 - HACK for demo mode: in physical (-p) mode, multiple consecutive formfeeds are suppressed.
16 This lets us do a formfeed at the end of a job to kick the last page out
17 without getting another blank page at the beginning of the next job.
19 2003.12.02 - Added -p option for physical line printer output (flushes
20 output buffer after each line). When using a physical printer on
21 Windows, be sure to set printer to "send output directly to printer"
22 to disable spooling, otherwise nothing appears until printer is
25 2003.11.25 - Changed magic filename for standard output to "(stdout)".
27 2002.09.13 - Added 1403 support. New file, taken from part of ibm1130_stddev.c
29 Note: The 1403 is much faster, even in emulation, because it takes much
30 less CPU power to run it. DMS doesn't use the WAIT command when waiting for
31 printer operations to complete, so it ends up burning LOTS of cpu cycles.
32 The 1403 printer doesn't require as many. HOWEVER: DMS must be loaded for the 1403,
33 and Fortran IOCS control cards must specify it.
35 The 1132 is still the default printer.
37 As written, we can't have two printers.
39 * (C) Copyright 2002, Brian Knittel.
40 * You may freely use this program, but: it offered strictly on an AS-IS, AT YOUR OWN
41 * RISK basis, there is no warranty of fitness for any purpose, and the rest of the
42 * usual yada-yada. Please keep this notice and the copyright in any distributions
45 * This is not a supported product, but I welcome bug reports and fixes.
46 * Mail to simh@ibm1130.org
49 #include "ibm1130_defs.h"
50 #include <stdlib.h> /* needed for atexit, for cgi mode */
52 /***************************************************************************************
54 ***************************************************************************************/
56 #define PRT1132_DSW_READ_EMITTER_RESPONSE 0x8000
57 #define PRT1132_DSW_SKIP_RESPONSE 0x4000
58 #define PRT1132_DSW_SPACE_RESPONSE 0x2000
59 #define PRT1132_DSW_CARRIAGE_BUSY 0x1000
60 #define PRT1132_DSW_PRINT_SCAN_CHECK 0x0800
61 #define PRT1132_DSW_NOT_READY 0x0400
62 #define PRT1132_DSW_PRINTER_BUSY 0x0200
64 #define PRT1132_DSW_CHANNEL_MASK 0x00FF /* 1132 printer DSW bits */
65 #define PRT1132_DSW_CHANNEL_1 0x0080
66 #define PRT1132_DSW_CHANNEL_2 0x0040
67 #define PRT1132_DSW_CHANNEL_3 0x0020
68 #define PRT1132_DSW_CHANNEL_4 0x0010
69 #define PRT1132_DSW_CHANNEL_5 0x0008
70 #define PRT1132_DSW_CHANNEL_6 0x0004
71 #define PRT1132_DSW_CHANNEL_9 0x0002
72 #define PRT1132_DSW_CHANNEL_12 0x0001
74 #define PRT1403_DSW_PARITY_CHECK 0x8000 /* 1403 printer DSW bits */
75 #define PRT1403_DSW_TRANSFER_COMPLETE 0x4000
76 #define PRT1403_DSW_PRINT_COMPLETE 0x2000
77 #define PRT1403_DSW_CARRIAGE_COMPLETE 0x1000
78 #define PRT1403_DSW_RING_CHECK 0x0400
79 #define PRT1403_DSW_SYNC_CHECK 0x0200
80 #define PRT1403_DSW_CH9 0x0010
81 #define PRT1403_DSW_CH12 0x0008
82 #define PRT1403_DSW_CARRIAGE_BUSY 0x0004
83 #define PRT1403_DSW_PRINTER_BUSY 0x0002
84 #define PRT1403_DSW_NOT_READY 0x0001
86 #define IS_ONLINE(u) (((u)->flags & (UNIT_ATT|UNIT_DIS)) == UNIT_ATT)
88 static t_stat
prt1132_svc(UNIT
*uptr
);
89 static t_stat
prt1403_svc(UNIT
*uptr
);
90 static t_stat
prt_svc (UNIT
*uptr
);
91 static t_stat
prt_reset (DEVICE
*dptr
);
92 static t_stat
prt_attach (UNIT
*uptr
, char *cptr
);
93 static t_stat
prt_detach (UNIT
*uptr
);
95 static int16 PRT_DSW
= 0; /* device status word */
96 static int32 prt_swait
= 500; /* line skip wait */
97 static int32 prt_cwait
= 1250; /* character rotation wait */
98 static int32 prt_fwait
= 100; /* fast wait, for 1403 operations */
99 static int32 prt_twait
= 50; /* transfer wait, for 1403 operations */
100 #define SKIPTARGET (uptr->u4) /* target for skip operation */
102 static t_bool formfed
= FALSE
; /* last line printed was a formfeed */
104 #define UNIT_V_FORMCHECK (UNIT_V_UF + 0) /* out of paper error */
105 #define UNIT_V_DATACHECK (UNIT_V_UF + 1) /* printer overrun error */
106 #define UNIT_V_SKIPPING (UNIT_V_UF + 2) /* printer skipping */
107 #define UNIT_V_SPACING (UNIT_V_UF + 3) /* printer is spacing */
108 #define UNIT_V_PRINTING (UNIT_V_UF + 4) /* printer printing */
109 #define UNIT_V_TRANSFERRING (UNIT_V_UF + 5) /* unit is transferring print buffer (1403 only) */
110 #define UNIT_V_1403 (UNIT_V_UF + 6) /* printer model is 1403 rather than 1132 */
111 #define UNIT_V_PARITYCHECK (UNIT_V_UF + 7) /* error flags for 1403 */
112 #define UNIT_V_RINGCHECK (UNIT_V_UF + 8)
113 #define UNIT_V_SYNCCHECK (UNIT_V_UF + 9)
114 #define UNIT_V_PHYSICAL_PTR (UNIT_V_UF + 10) /* this appears in ibm1130_gui as well */
116 #define UNIT_FORMCHECK (1u << UNIT_V_FORMCHECK)
117 #define UNIT_DATACHECK (1u << UNIT_V_DATACHECK)
118 #define UNIT_SKIPPING (1u << UNIT_V_SKIPPING)
119 #define UNIT_SPACING (1u << UNIT_V_SPACING)
120 #define UNIT_PRINTING (1u << UNIT_V_PRINTING)
121 #define UNIT_TRANSFERRING (1u << UNIT_V_TRANSFERRING)
122 #define UNIT_1403 (1u << UNIT_V_1403)
123 #define UNIT_PARITYCHECK (1u << UNIT_V_PARITYCHECK)
124 #define UNIT_RINGCHECK (1u << UNIT_V_RINGCHECK)
125 #define UNIT_SYNCCHECK (1u << UNIT_V_SYNCCHECK)
126 #define UNIT_PHYSICAL_PTR (1u << UNIT_V_PHYSICAL_PTR)
129 { UDATA (&prt_svc
, UNIT_ATTABLE
, 0) },
132 #define IS_1403(uptr) (uptr->flags & UNIT_1403) /* model test */
133 #define IS_1132(uptr) ((uptr->flags & UNIT_1403) == 0) /* model test */
134 #define IS_PHYSICAL(uptr) (uptr->flags & UNIT_PHYSICAL_PTR)
136 /* Parameter in the unit descriptor (1132 printer) */
144 { HRDATA (PRTDSW
, PRT_DSW
, 16) }, /* device status word */
145 { DRDATA (STIME
, prt_swait
, 24), PV_LEFT
}, /* line skip wait */
146 { DRDATA (CTIME
, prt_cwait
, 24), PV_LEFT
}, /* character rotation wait */
147 { DRDATA (FTIME
, prt_fwait
, 24), PV_LEFT
}, /* 1403 fast wait */
148 { DRDATA (TTIME
, prt_twait
, 24), PV_LEFT
}, /* 1403 transfer wait */
152 { UNIT_1403
, 0, "1132", "1132", NULL
}, /* model option */
153 { UNIT_1403
, UNIT_1403
, "1403", "1403", NULL
},
157 "PRT", prt_unit
, prt_reg
, prt_mod
,
158 1, 16, 16, 1, 16, 16,
159 NULL
, NULL
, &prt_reset
,
160 NULL
, prt_attach
, prt_detach
};
162 #define MAX_COLUMNS 120
163 #define MAX_OVPRINT 20
164 #define PRT1132_COLUMNS 120
165 #define PRT1403_COLUMNS 120 /* the 1130's version of the 1403 printed in 120 columns only (see Functional Characteristics) */
167 static char prtbuf
[MAX_COLUMNS
*MAX_OVPRINT
];
168 static int nprint
[MAX_COLUMNS
], ncol
[MAX_OVPRINT
], maxnp
;
169 static int prt_nchar
, prt_row
; /* current printwheel position, current page row */
170 static int prt_nnl
; /* number of queued newlines */
172 #define CC_CHANNEL_1 0x0800 /* carriage control tape punch values */
173 #define CC_CHANNEL_2 0x0400
174 #define CC_CHANNEL_3 0x0200
175 #define CC_CHANNEL_4 0x0100
176 #define CC_CHANNEL_5 0x0080
177 #define CC_CHANNEL_6 0x0040 /* 7, 8, 10 and 11 are not used on 1132 printer */
178 #define CC_CHANNEL_7 0x0020
179 #define CC_CHANNEL_8 0x0010
180 #define CC_CHANNEL_9 0x0008
181 #define CC_CHANNEL_10 0x0004
182 #define CC_CHANNEL_11 0x0002
183 #define CC_CHANNEL_12 0x0001
185 #define CC_1403_BITS 0x0FFF /* all bits for 1403, most for 1132 */
186 #define CC_1132_BITS (CC_1403_BITS & ~(CC_CHANNEL_7|CC_CHANNEL_8|CC_CHANNEL_10|CC_CHANNEL_11))
188 #define PRT_PAGELENGTH 66
190 static int cctape
[PRT_PAGELENGTH
]; /* standard carriage control tape */
192 static struct tag_ccpunches
{ /* list of rows and punches on tape */
196 2, CC_CHANNEL_1
, /* channel 1 = top of form */
197 62, CC_CHANNEL_12
/* channel 12 = bottom of form */
200 2, CC_CHANNEL_1
/* channel 1 = top of form; no bottom of form */
203 #include "ibm1130_prtwheel.h"
205 extern int32 sim_switches
;
207 /* cc_format_1132 and cc_format_1403 - turn cctape bits into proper format for DSW or status read */
209 static int cc_format_1132 (int bits
)
211 return ((bits
& (CC_CHANNEL_1
|CC_CHANNEL_2
|CC_CHANNEL_3
|CC_CHANNEL_4
|CC_CHANNEL_5
|CC_CHANNEL_6
)) >> 4) |
212 ((bits
& CC_CHANNEL_9
) >> 3) |
213 (bits
& CC_CHANNEL_12
);
216 #define cc_format_1403(bits) (bits)
218 /* reset_prt_line - clear the print line following paper advancement */
220 static void reset_prt_line (void)
222 memset(nprint
, 0, sizeof(nprint
));
223 memset(ncol
, 0, sizeof(ncol
));
227 /* save_1132_prt_line - fire hammers for character 'ch' */
229 static t_bool
save_1132_prt_line (int ch
)
232 int32 mask
= 0, wd
= 0;
234 for (i
= 0; i
< PRT1132_COLUMNS
; i
++) {
235 if (mask
== 0) { /* fetch next word from memory */
240 if (wd
& mask
) { /* hammer is to fire in this column */
241 if ((r
= nprint
[i
]) < MAX_OVPRINT
) {
242 if (ncol
[r
] <= i
) { /* we haven't moved this far yet */
243 if (ncol
[r
] == 0) /* first char in this row? */
244 memset(prtbuf
+r
*MAX_COLUMNS
, ' ', PRT1132_COLUMNS
); /* blank out the new row */
245 ncol
[r
] = i
+1; /* remember new row length */
247 prtbuf
[r
*MAX_COLUMNS
+ i
] = (char) ch
; /* save the character */
249 nprint
[i
]++; /* remember max overprintings for this column */
250 maxnp
= MAX(maxnp
, nprint
[i
]);
254 mask
>>= 1; /* prepare to examine next bit */
257 return wd
& 1; /* return TRUE if the last word has lsb set, which means all bits had been set */
260 /* write_line - write collected line to output file. No need to trim spaces as the hammers
261 * are never fired for them, so ncol[r] is the last printed position on each line.
264 static void newpage (FILE *fd
, t_bool physical_printer
)
268 else if (! formfed
) {
270 if (physical_printer
) {
271 fflush(fd
); /* send the ff out to the printer immediately */
272 formfed
= TRUE
; /* hack: inhibit consecutive ff's */
277 static void flush_prt_line (FILE *fd
, int spacemode
, t_bool physical_printer
)
281 if (! (spacemode
|| maxnp
)) /* nothing to do */
284 prt_row
= (prt_row
+1) % PRT_PAGELENGTH
; /* NEXT line */
286 if (spacemode
&& ! maxnp
) { /* spacing only */
287 if (prt_row
== 0 && prt_nnl
) {
290 putc('\r', fd
); /* DOS/Windows: end with cr/lf */
292 putc('\n', fd
); /* otherwise end with lf */
293 if (spacemode
& UNIT_SKIPPING
) /* add formfeed if we crossed page boundary while skipping */
294 newpage(fd
, physical_printer
);
303 prt_unit
->pos
++; /* note something written */
307 if (prt_nnl
) { /* there are queued newlines */
308 while (prt_nnl
> 0) { /* spit out queued newlines */
311 putc('\r', fd
); /* DOS/Windows: end with cr/lf */
313 putc('\n', fd
); /* otherwise end with lf */
318 for (r
= 0; r
< maxnp
; r
++) {
320 putc('\r', fd
); /* carriage return between overprinted lines */
322 fxwrite(&prtbuf
[r
*MAX_COLUMNS
], 1, ncol
[r
], fd
);
327 prt_unit
->pos
++; /* note something written */
328 prt_nnl
++; /* queue a newline */
330 if (physical_printer
) /* if physical printer, send buffered output to device */
333 formfed
= FALSE
; /* note that something is now on the page */
336 /* 1132 printer commands */
338 #define PRT_CMD_START_PRINTER 0x0080
339 #define PRT_CMD_STOP_PRINTER 0x0040
340 #define PRT_CMD_START_CARRIAGE 0x0004
341 #define PRT_CMD_STOP_CARRIAGE 0x0002
342 #define PRT_CMD_SPACE 0x0001
344 #define PRT_CMD_MASK 0x00C7
346 extern char * saywhere (int addr
);
348 static void mytrace (int start
, char *what
)
352 if ((where
= saywhere(prev_IAR
)) == NULL
) where
= "?";
353 trace_io("%s %s at %04x: %s\n", start
? "start" : "stop", what
, prev_IAR
, where
);
356 /* xio_1132_printer - XIO command interpreter for the 1132 printer */
358 void xio_1132_printer (int32 iocc_addr
, int32 func
, int32 modify
)
361 UNIT
*uptr
= &prt_unit
[0];
365 M
[iocc_addr
& mem_mask
] = codewheel1132
[prt_nchar
].ebcdic
<< 8;
367 if ((uptr
->flags
& UNIT_PRINTING
) == 0) /* if we're not printing, advance this after every test */
368 prt_nchar
= (prt_nchar
+ 1) % WHEELCHARS_1132
;
373 if (modify
& 0x01) { /* reset interrupts */
374 CLRBIT(PRT_DSW
, PRT1132_DSW_READ_EMITTER_RESPONSE
| PRT1132_DSW_SKIP_RESPONSE
| PRT1132_DSW_SPACE_RESPONSE
);
375 CLRBIT(ILSW
[1], ILSW_1_1132_PRINTER
);
380 if (modify
& PRT_CMD_START_PRINTER
) {
381 SETBIT(uptr
->flags
, UNIT_PRINTING
);
382 /* mytrace(1, "printing"); */
385 if (modify
& PRT_CMD_STOP_PRINTER
) {
386 CLRBIT(uptr
->flags
, UNIT_PRINTING
);
387 /* mytrace(0, "printing"); */
390 if (modify
& PRT_CMD_START_CARRIAGE
) {
391 SETBIT(uptr
->flags
, UNIT_SKIPPING
);
392 /* mytrace(1, "skipping"); */
395 if (modify
& PRT_CMD_STOP_CARRIAGE
) {
396 CLRBIT(uptr
->flags
, UNIT_SKIPPING
);
397 /* mytrace(0, "skipping"); */
400 if (modify
& PRT_CMD_SPACE
) {
401 SETBIT(uptr
->flags
, UNIT_SPACING
);
402 /* mytrace(1, "space"); */
406 if (uptr
->flags
& (UNIT_SKIPPING
|UNIT_SPACING
|UNIT_PRINTING
)) { /* busy bits = doing something */
407 SETBIT(PRT_DSW
, PRT1132_DSW_PRINTER_BUSY
);
408 sim_activate(uptr
, prt_cwait
);
411 CLRBIT(PRT_DSW
, PRT1132_DSW_PRINTER_BUSY
);
413 if (uptr
->flags
& (UNIT_SKIPPING
|UNIT_SPACING
))
414 SETBIT(PRT_DSW
, PRT1132_DSW_CARRIAGE_BUSY
);
416 CLRBIT(PRT_DSW
, PRT1132_DSW_CARRIAGE_BUSY
);
418 if ((uptr
->flags
& (UNIT_SKIPPING
|UNIT_SPACING
)) == (UNIT_SKIPPING
|UNIT_SPACING
)) {
419 sprintf(msg
, "1132 printer skip and space at same time?");
425 sprintf(msg
, "Invalid 1132 printer XIO function %x", func
);
430 #define SET_ACTION(u,a) {(u)->flags &= ~(UNIT_SKIPPING|UNIT_SPACING|UNIT_PRINTING|UNIT_TRANSFERRING); (u)->flags |= a;}
432 static t_stat
prt_svc (UNIT
*uptr
)
434 return IS_1403(uptr
) ? prt1403_svc(uptr
) : prt1132_svc(uptr
);
437 /* prt1132_svc - emulated timeout for 1132 operation */
439 static t_stat
prt1132_svc (UNIT
*uptr
)
441 if (PRT_DSW
& PRT1132_DSW_NOT_READY
) { /* cancel operation if printer went offline */
442 SETBIT(uptr
->flags
, UNIT_FORMCHECK
);
444 forms_check(TRUE
); /* and turn on forms check lamp */
448 if (uptr
->flags
& UNIT_SPACING
) {
449 flush_prt_line(uptr
->fileref
, UNIT_SPACING
, IS_PHYSICAL(uptr
));
451 CLRBIT(PRT_DSW
, PRT1132_DSW_CHANNEL_MASK
|PRT1132_DSW_PRINTER_BUSY
|PRT1132_DSW_CARRIAGE_BUSY
);
452 SETBIT(PRT_DSW
, cc_format_1132(cctape
[prt_row
]) | PRT1132_DSW_SPACE_RESPONSE
);
453 SETBIT(ILSW
[1], ILSW_1_1132_PRINTER
);
454 CLRBIT(uptr
->flags
, UNIT_SPACING
); /* done with this */
458 if (uptr
->flags
& UNIT_SKIPPING
) {
460 flush_prt_line(uptr
->fileref
, UNIT_SKIPPING
, IS_PHYSICAL(uptr
));
461 CLRBIT(PRT_DSW
, PRT1132_DSW_CHANNEL_MASK
);
462 SETBIT(PRT_DSW
, cc_format_1132(cctape
[prt_row
]));
463 } while ((cctape
[prt_row
] & CC_1132_BITS
) == 0); /* slew directly to a cc tape punch */
465 SETBIT(PRT_DSW
, cc_format_1132(cctape
[prt_row
]) | PRT1132_DSW_SKIP_RESPONSE
);
466 SETBIT(ILSW
[1], ILSW_1_1132_PRINTER
);
470 if (uptr
->flags
& UNIT_PRINTING
) {
471 if (! save_1132_prt_line(codewheel1132
[prt_nchar
].ascii
)) { /* save previous printed line */
472 SETBIT(uptr
->flags
, UNIT_DATACHECK
); /* buffer wasn't set in time */
474 print_check(TRUE
); /* and turn on forms check lamp */
478 prt_nchar
= (prt_nchar
+ 1) % WHEELCHARS_1132
; /* advance print drum */
480 SETBIT(PRT_DSW
, PRT1132_DSW_READ_EMITTER_RESPONSE
); /* issue interrupt to tell printer to set buffer */
481 SETBIT(ILSW
[1], ILSW_1_1132_PRINTER
); /* we'll save the printed stuff just before next emitter response (later than on real 1130) */
485 if (uptr
->flags
& (UNIT_SPACING
|UNIT_SKIPPING
|UNIT_PRINTING
)) { /* still doing something */
486 SETBIT(PRT_DSW
, PRT1132_DSW_PRINTER_BUSY
);
487 sim_activate(uptr
, prt_cwait
);
490 CLRBIT(PRT_DSW
, PRT1132_DSW_PRINTER_BUSY
);
495 void save_1403_prt_line (int32 addr
)
497 int i
, j
, r
, ch
, even
= TRUE
;
498 unsigned char ebcdic
;
501 for (i
= 0; i
< PRT1403_COLUMNS
; i
++) {
502 if (even
) { /* fetch next word from memory */
504 ebcdic
= (unsigned char) ((wd
>> 8) & 0x7F);
508 ebcdic
= (unsigned char) (wd
& 0x7F); /* use low byte of previously fetched word */
512 ch
= ' '; /* translate ebcdic to ascii. Don't bother checking for parity errors */
513 for (j
= 0; j
< WHEELCHARS_1403
; j
++) {
514 if (codewheel1403
[j
].ebcdic
== ebcdic
) {
515 ch
= codewheel1403
[j
].ascii
;
521 if ((r
= nprint
[i
]) < MAX_OVPRINT
) {
522 if (ncol
[r
] <= i
) { /* we haven't moved this far yet */
523 if (ncol
[r
] == 0) /* first char in this row? */
524 memset(prtbuf
+r
*MAX_COLUMNS
, ' ', PRT1403_COLUMNS
); /* blank out the new row */
525 ncol
[r
] = i
+1; /* remember new row length */
527 prtbuf
[r
*MAX_COLUMNS
+ i
] = (char) ch
; /* save the character */
529 nprint
[i
]++; /* remember max overprintings for this column */
530 maxnp
= MAX(maxnp
, nprint
[i
]);
536 void xio_1403_printer (int32 iocc_addr
, int32 func
, int32 modify
)
538 UNIT
*uptr
= &prt_unit
[0];
541 case XIO_INITW
: /* print a line */
542 save_1403_prt_line(iocc_addr
); /* put formatted line into our print buffer */
544 SETBIT(uptr
->flags
, UNIT_TRANSFERRING
); /* schedule transfer complete interrupt */
545 SETBIT(PRT_DSW
, PRT1403_DSW_PRINTER_BUSY
);
546 sim_activate(uptr
, prt_twait
);
549 case XIO_CONTROL
: /* initiate single space */
550 if (uptr
->flags
& UNIT_SKIPPING
) {
551 xio_error("1403 printer skip and space at same time?");
554 SETBIT(uptr
->flags
, UNIT_SPACING
);
555 SETBIT(PRT_DSW
, PRT1403_DSW_CARRIAGE_BUSY
);
556 sim_activate(uptr
, prt_fwait
);
560 case XIO_WRITE
: /* initiate skip */
561 if (uptr
->flags
& UNIT_SPACING
) {
562 xio_error("1403 printer skip and space at same time?");
565 SETBIT(uptr
->flags
, UNIT_SKIPPING
);
566 SKIPTARGET
= ReadW(iocc_addr
) & CC_1403_BITS
; /* get CC bits that we're to match */
567 SETBIT(PRT_DSW
, PRT1403_DSW_CARRIAGE_BUSY
);
568 sim_activate(uptr
, prt_fwait
);
572 case XIO_SENSE_DEV
: /* get device status word */
574 if (modify
& 0x01) { /* reset interrupts */
575 CLRBIT(PRT_DSW
, PRT1403_DSW_PARITY_CHECK
| PRT1403_DSW_TRANSFER_COMPLETE
|
576 PRT1403_DSW_PRINT_COMPLETE
| PRT1403_DSW_CARRIAGE_COMPLETE
|
577 PRT1403_DSW_RING_CHECK
| PRT1403_DSW_SYNC_CHECK
);
578 CLRBIT(ILSW
[4], ILSW_4_1403_PRINTER
);
584 static t_stat
prt1403_svc(UNIT
*uptr
)
586 if (PRT_DSW
& PRT1403_DSW_NOT_READY
) { /* cancel operation if printer went offline */
588 forms_check(TRUE
); /* and turn on forms check lamp */
590 else if (uptr
->flags
& UNIT_TRANSFERRING
) { /* end of transfer */
591 CLRBIT(uptr
->flags
, UNIT_TRANSFERRING
);
592 SETBIT(uptr
->flags
, UNIT_PRINTING
); /* schedule "print complete" */
594 SETBIT(PRT_DSW
, PRT1403_DSW_TRANSFER_COMPLETE
); /* issue transfer complete interrupt */
595 SETBIT(ILSW
[4], ILSW_4_1403_PRINTER
);
597 else if (uptr
->flags
& UNIT_PRINTING
) {
598 CLRBIT(uptr
->flags
, UNIT_PRINTING
);
599 CLRBIT(PRT_DSW
, PRT1403_DSW_PRINTER_BUSY
);
601 SETBIT(PRT_DSW
, PRT1403_DSW_PRINT_COMPLETE
);
602 SETBIT(ILSW
[4], ILSW_4_1403_PRINTER
); /* issue print complete interrupt */
604 else if (uptr
->flags
& UNIT_SKIPPING
) {
605 do { /* find line with exact match of tape punches */
606 flush_prt_line(uptr
->fileref
, UNIT_SKIPPING
, IS_PHYSICAL(uptr
));
607 } while (cctape
[prt_row
] != SKIPTARGET
); /* slew directly to requested cc tape punch */
609 CLRBIT(uptr
->flags
, UNIT_SKIPPING
); /* done with this */
610 CLRBIT(PRT_DSW
, PRT1403_DSW_CARRIAGE_BUSY
);
612 SETBIT(PRT_DSW
, PRT1403_DSW_CARRIAGE_COMPLETE
);
613 SETBIT(ILSW
[4], ILSW_4_1403_PRINTER
);
615 else if (uptr
->flags
& UNIT_SPACING
) {
616 flush_prt_line(uptr
->fileref
, UNIT_SPACING
, IS_PHYSICAL(uptr
));
618 CLRBIT(uptr
->flags
, UNIT_SPACING
); /* done with this */
619 CLRBIT(PRT_DSW
, PRT1403_DSW_CARRIAGE_BUSY
);
621 SETBIT(PRT_DSW
, PRT1403_DSW_CARRIAGE_COMPLETE
);
622 SETBIT(ILSW
[4], ILSW_4_1403_PRINTER
);
625 if (uptr
->flags
& (UNIT_PRINTING
|UNIT_SKIPPING
|UNIT_SPACING
|UNIT_TRANSFERRING
))
626 sim_activate(uptr
, prt_fwait
);
628 CLRBIT(PRT_DSW
, PRT1403_DSW_CH9
|PRT1403_DSW_CH12
); /* set the two CC bits in the DSW */
629 if (cctape
[prt_row
] & CC_CHANNEL_9
)
630 SETBIT(PRT_DSW
, PRT1403_DSW_CH9
);
631 if (cctape
[prt_row
] & CC_CHANNEL_12
)
632 SETBIT(PRT_DSW
, PRT1403_DSW_CH12
);
638 /* delete_cmd - SCP command to delete a file */
640 static t_stat
delete_cmd (int flag
, char *cptr
)
645 cptr
= get_glyph (cptr
, gbuf
, 0); /* get next glyph */
646 if (*gbuf
== 0) return SCPE_2FARG
;
647 if (*cptr
!= 0) return SCPE_2MARG
; /* now eol? */
649 status
= remove(gbuf
); /* delete the file */
651 if (status
!= 0 && errno
!= ENOENT
) /* print message if failed and file exists */
657 /* prt_reset - reset emulated printer */
659 static t_stat
prt_reset (DEVICE
*dptr
)
661 UNIT
*uptr
= &prt_unit
[0];
664 /* add a DELETE filename command so we can be sure to have clean listings */
665 register_cmd("DELETE", &delete_cmd
, 0, "del{ete} filename remove file\n");
669 memset(cctape
, 0, sizeof(cctape
)); /* copy punch list into carriage control tape image */
672 for (i
= 0; i
< (sizeof(cccgi
)/sizeof(cccgi
[0])); i
++)
673 cctape
[cccgi
[i
].row
-1] |= cccgi
[i
].channels
;
676 for (i
= 0; i
< (sizeof(ccpunches
)/sizeof(ccpunches
[0])); i
++)
677 cctape
[ccpunches
[i
].row
-1] |= ccpunches
[i
].channels
;
683 CLRBIT(uptr
->flags
, UNIT_FORMCHECK
|UNIT_DATACHECK
|UNIT_PRINTING
|UNIT_SPACING
|UNIT_SKIPPING
|
684 UNIT_TRANSFERRING
|UNIT_PARITYCHECK
|UNIT_RINGCHECK
|UNIT_SYNCCHECK
);
687 CLRBIT(ILSW
[1], ILSW_1_1132_PRINTER
);
688 PRT_DSW
= cc_format_1132(cctape
[prt_row
]);
689 if (! IS_ONLINE(uptr
))
690 SETBIT(PRT_DSW
, PRT1132_DSW_NOT_READY
);
693 CLRBIT(ILSW
[4], ILSW_4_1403_PRINTER
);
695 if (cctape
[prt_row
] & CC_CHANNEL_9
)
696 SETBIT(PRT_DSW
, PRT1403_DSW_CH9
);
697 if (cctape
[prt_row
] & CC_CHANNEL_12
)
698 SETBIT(PRT_DSW
, PRT1403_DSW_CH12
);
699 if (! IS_ONLINE(uptr
))
700 SETBIT(PRT_DSW
, PRT1403_DSW_NOT_READY
);
711 static t_stat
prt_attach (UNIT
*uptr
, char *cptr
)
715 SETBIT(PRT_DSW
, IS_1132(uptr
) ? PRT1132_DSW_NOT_READY
: PRT1403_DSW_NOT_READY
);
718 if (uptr
->flags
& UNIT_ATT
) {
719 if ((rval
= prt_detach(uptr
)) != SCPE_OK
) {
724 if (sim_switches
& SWMASK('P')) /* set physical (unbuffered) printer flag */
725 SETBIT(uptr
->flags
, UNIT_PHYSICAL_PTR
);
727 CLRBIT(uptr
->flags
, UNIT_PHYSICAL_PTR
);
731 if (strcmp(cptr
, "(stdout)") == 0) { /* connect printer to stdout */
732 if (uptr
-> flags
& UNIT_DIS
) return SCPE_UDIS
; /* disabled? */
733 uptr
->filename
= calloc(CBUFSIZE
, sizeof(char));
734 strcpy(uptr
->filename
, "(stdout)");
735 uptr
->fileref
= stdout
;
736 SETBIT(uptr
->flags
, UNIT_ATT
);
740 if ((rval
= attach_unit(uptr
, quotefix(cptr
))) != SCPE_OK
)
744 fseek(uptr
->fileref
, 0, SEEK_END
); /* if we opened an existing file, append to it */
745 uptr
->pos
= ftell(uptr
->fileref
);
748 CLRBIT(ILSW
[1], ILSW_1_1132_PRINTER
);
749 CLRBIT(uptr
->flags
, UNIT_FORMCHECK
|UNIT_DATACHECK
);
752 CLRBIT(ILSW
[4], ILSW_4_1403_PRINTER
);
753 CLRBIT(uptr
->flags
, UNIT_PARITYCHECK
|UNIT_RINGCHECK
|UNIT_SYNCCHECK
);
765 PRT_DSW
= (PRT_DSW
& ~PRT1132_DSW_CHANNEL_MASK
) | cc_format_1132(cctape
[prt_row
]);
768 CLRBIT(PRT_DSW
, PRT1132_DSW_NOT_READY
);
771 CLRBIT(PRT_DSW
, PRT1403_DSW_CH9
| PRT1403_DSW_CH12
);
772 if (cctape
[prt_row
] & CC_CHANNEL_9
)
773 SETBIT(PRT_DSW
, PRT1403_DSW_CH9
);
774 if (cctape
[prt_row
] & CC_CHANNEL_12
)
775 SETBIT(PRT_DSW
, PRT1403_DSW_CH12
);
778 CLRBIT(PRT_DSW
, PRT1403_DSW_NOT_READY
); /* fixed by Carl Claunch */
786 static t_stat
prt_detach (UNIT
*uptr
)
790 if (uptr
->flags
& UNIT_ATT
)
791 flush_prt_line(uptr
->fileref
, TRUE
, TRUE
);
793 if (uptr
->fileref
== stdout
) {
794 CLRBIT(uptr
->flags
, UNIT_ATT
);
795 free(uptr
->filename
);
796 uptr
->filename
= NULL
;
798 else if ((rval
= detach_unit(uptr
)) != SCPE_OK
)
804 CLRBIT(ILSW
[1], ILSW_1_1132_PRINTER
);
805 CLRBIT(uptr
->flags
, UNIT_FORMCHECK
|UNIT_DATACHECK
);
806 SETBIT(PRT_DSW
, PRT1132_DSW_NOT_READY
);
809 CLRBIT(ILSW
[4], ILSW_4_1403_PRINTER
);
810 SETBIT(PRT_DSW
, PRT1403_DSW_NOT_READY
);