t_stat write_line (int32 ilnt, int32 mod) { int32 i, t, wm, sup; char *bcd2asc; static char lbuf[LPT_WIDTH + 1]; /* + null */ if ((lpt_unit.flags & UNIT_ATT) == 0) /* attached? */ return SCPE_UNATT; wm = ((ilnt == 2) || (ilnt == 5)) && (mod == BCD_SQUARE); sup = ((ilnt == 2) || (ilnt == 5)) && (mod == BCD_S); ind[IN_LPT] = 0; /* clear error */ if (conv_old) /* get print chain */ bcd2asc = pch_table_old[GET_PCHAIN (lpt_unit.flags)]; else bcd2asc = pch_table[GET_PCHAIN (lpt_unit.flags)]; for (i = 0; i < LPT_WIDTH; i++) { /* convert print buf */ t = M[LPT_BUF + i]; if (wm) /* wmarks -> 1 or sp */ lbuf[i] = (t & WM)? '1': ' '; else lbuf[i] = bcd2asc[t & CHAR]; /* normal */ } lbuf[LPT_WIDTH] = 0; /* trailing null */ for (i = LPT_WIDTH - 1; (i >= 0) && (lbuf[i] == ' '); i--) lbuf[i] = 0; fputs (lbuf, lpt_unit.fileref); /* write line */ if (lines) /* cc action? do it */ space (lines, lflag); else if (sup == 0) /* default? 1 line */ space (1, FALSE); else { fputc ('\r', lpt_unit.fileref); /* sup -> overprint */ lpt_unit.pos = ftell (lpt_unit.fileref); /* update position */ } lines = lflag = 0; /* clear cc action */ if (ferror (lpt_unit.fileref)) { /* error? */ ind[IN_LPT] = 1; perror ("Line printer I/O error"); clearerr (lpt_unit.fileref); if (iochk) return SCPE_IOERR; } return SCPE_OK; }
t_stat lpt_end_line (UNIT *uptr) { uint32 i, col, row, bufw, colbin; const char *pch; char bcd, lpt_cbuf[LPT_CHRLNT + 1]; t_uint64 dat; pch = pch_table[GET_PCHAIN (lpt_unit.flags)]; /* get print chain */ for (col = 0; col < (LPT_CHRLNT + 1); col++) /* clear ascii buf */ lpt_cbuf[col] = ' '; for (col = 0; col < 72; col++) { /* proc 72 columns */ colbin = 0; dat = bit_masks[35 - (col % 36)]; /* mask for column */ for (row = 0; row < 12; row++) { /* proc 12 rows */ bufw = (row * 2) + (col / 36); /* index to buffer */ if (lpt_bbuf[bufw] & dat) colbin |= col_masks[row]; } bcd = colbin_to_bcd (colbin); /* column bin -> BCD */ lpt_cbuf[col] = pch[bcd]; /* -> ASCII */ } for (i = LPT_CHRLNT; (i > 0) && (lpt_cbuf[i - 1] == ' '); --i) ; /* trim spaces */ lpt_cbuf[i] = 0; /* append nul */ if (uptr->flags & UNIT_ATT) { /* file? */ fputs (lpt_cbuf, uptr->fileref); /* write line */ fputc ('\n', uptr->fileref); /* append nl */ uptr->pos = ftell (uptr->fileref); /* update position */ if (ferror (uptr->fileref)) { /* error? */ sim_perror ("LPT I/O error"); clearerr (uptr->fileref); return SCPE_IOERR; } } else if (uptr->flags & UNIT_CONS) { /* print to console? */ for (i = 0; lpt_cbuf[i] != 0; i++) sim_putchar (lpt_cbuf[i]); sim_putchar ('\r'); sim_putchar ('\n'); } else return SCPE_UNATT; /* otherwise error */ lpt_sta = LPS_END; /* end line state */ sim_cancel (uptr); /* cancel current */ sim_activate (uptr, lpt_tstop); /* long timer */ return SCPE_OK; }