t_stat ptr_svc (UNIT *uptr) { int32 temp; if ((ptr_unit.flags & UNIT_ATT) == 0) { /* attached? */ ptr_set_err (); /* no, err, disc */ CRETIOE (ptr_stopioe, SCPE_UNATT); } if ((temp = getc (ptr_unit.fileref)) == EOF) { /* end of file? */ ptr_set_err (); /* yes, err, disc */ if (feof (ptr_unit.fileref)) { /* end of file? */ if (ptr_stopioe) sim_printf ("PTR end of file\n"); else return SCPE_OK; } else perror ("PTR I/O error"); /* I/O error */ clearerr (ptr_unit.fileref); return SCPE_IOERR; } ptr_unit.pos = ptr_unit.pos + 1; /* inc position */ if (temp) { /* leader/gap? */ ptr_unit.buf = temp & 0177; /* no, save char */ xfr_req = xfr_req | XFR_PTR; /* set xfr flag */ ptr_sor = 0; /* in record */ } else if (!ptr_sor) /* end record? */ chan_set_flag (ptr_dib.chan, CHF_EOR); /* ignore leader */ sim_activate (&ptr_unit, ptr_unit.wait); /* get next char */ return SCPE_OK; }
void ptp_set_err (void) { chan_set_flag (ptp_dib.chan, CHF_ERR); /* error */ chan_disc (ptp_dib.chan); /* disconnect */ xfr_req = xfr_req & ~XFR_PTP; /* clear xfr */ sim_cancel (&ptp_unit); /* stop */ return; }
void mt_set_err (UNIT *uptr) { chan_set_flag (mt_dib.chan, CHF_EOR | CHF_ERR); /* eor, error */ chan_disc (mt_dib.chan); /* disconnect */ xfr_req = xfr_req & ~XFR_MT0; /* clear xfr */ sim_cancel (uptr); /* stop */ mt_bptr = 0; /* buf empty */ return; }
void lpt_end_op (int32 fl) { if (fl) /* set flags */ chan_set_flag (lpt_dib.chan, fl); xfr_req = xfr_req & ~XFR_LPT; /* clear xfr */ sim_cancel (&lpt_unit); /* stop */ if (fl & CHF_ERR) { /* error? */ chan_disc (lpt_dib.chan); /* disconnect */ lpt_err = 1; /* set lpt err */ } return; }
void mt_readend (UNIT *uptr) { sim_cancel (uptr); /* stop timer */ mt_skip = 0; /* clr skp flg */ chan_set_flag (mt_dib.chan, CHF_EOR); /* end record */ if (mt_eof) /* EOF? */ chan_disc (mt_dib.chan); else { mt_gap = 1; /* no, in gap */ sim_activate (uptr, mt_gtime); /* start timer */ } return; }
t_stat lpt_svc (UNIT *uptr) { t_stat r = SCPE_OK; if (lpt_sta & SET_XFR) /* need lpt xfr? */ chan_set_ordy (lpt_dib.chan); if (lpt_sta & SET_EOR) { /* printing? */ chan_set_flag (lpt_dib.chan, CHF_EOR); /* set eor flg */ r = lpt_bufout (uptr); /* output buf */ } if (lpt_sta & SET_SPC) { /* spacing? */ if (uptr->flags & UNIT_ATT) { /* attached? */ int32 ln = LPT_GETLN (lpt_spc); /* get lines, ch */ if (lpt_spc & 0200) /* n lines? */ lpt_space (uptr, ln); /* upspace */ else lpt_crctl (uptr, ln); /* carriage ctl */ } r = lpt_status (uptr); /* update status */ } lpt_sta = 0; /* clear state */ return r; }
t_stat ptr (uint32 fnc, uint32 inst, uint32 *dat) { int32 new_ch; switch (fnc) { /* case function */ case IO_CONN: /* connect */ new_ch = I_GETEOCH (inst); /* get new chan */ if (new_ch != ptr_dib.chan) /* inv conn? err */ return SCPE_IERR; ptr_sor = 1; /* start of rec */ xfr_req = xfr_req & ~XFR_PTR; /* clr xfr flag */ sim_activate (&ptr_unit, ptr_unit.wait); /* activate */ break; case IO_DISC: /* disconnect */ ptr_sor = 0; /* clear state */ xfr_req = xfr_req & ~XFR_PTR; /* clr xfr flag */ sim_cancel (&ptr_unit); /* deactivate unit */ break; case IO_READ: /* read */ xfr_req = xfr_req & ~XFR_PTR; /* clr xfr flag */ *dat = ptr_unit.buf & 077; /* get buf data */ if (ptr_unit.buf != odd_par[*dat]) /* good parity? */ chan_set_flag (ptr_dib.chan, CHF_ERR); /* no, error */ break; case IO_WREOR: /* write eor */ break; case IO_EOM1: /* EOM mode 1*/ case IO_WRITE: /* write */ CRETINS; /* error */ } return SCPE_OK; }
t_stat mt (uint32 fnc, uint32 inst, uint32 *dat) { int32 u = inst & MT_UNIT; /* get unit */ UNIT *uptr = mt_dev.units + u; /* get unit ptr */ int32 t, new_ch; uint8 chr; t_stat r; switch (fnc) { /* case function */ case IO_CONN: /* connect */ new_ch = I_GETEOCH (inst); /* get new chan */ if (new_ch != mt_dib.chan) /* wrong chan? */ return SCPE_IERR; if (mt_gap) { /* in gap? */ mt_gap = 0; /* clr gap flg */ sim_cancel (uptr); /* cancel timer */ } else if (sim_is_active (uptr)) /* busy? */ CRETIOP; uptr->eotf = 0; /* clr eot flag */ mt_eof = 0; /* clr eof flag */ mt_skip = 0; /* clr skp flag */ mt_bptr = mt_blnt = 0; /* init buffer */ if ((inst & DEV_MTS)? (CHC_GETCPW (inst) < 2): /* scn & cpw<3? */ (inst & CHC_REV)) /* rw & rev? */ return STOP_INVIOP; mt_inst = inst; /* save inst */ if ((inst & DEV_MTS) && !(inst & DEV_OUT)) /* scanning? */ chan_set_flag (mt_dib.chan, CHF_SCAN); /* set chan flg */ xfr_req = xfr_req & ~XFR_MT0; /* clr xfr flag */ sim_activate (uptr, mt_gtime); /* start timer */ break; case IO_EOM1: /* EOM mode 1 */ new_ch = I_GETEOCH (inst); /* get new chan */ if (new_ch != mt_dib.chan) /* wrong chan? */ CRETIOP; t = inst & 07670; /* get command */ if ((t == 04010) && !sim_is_active (uptr)) { /* rewind? */ sim_tape_rewind (uptr); /* rewind unit */ uptr->eotf = 0; /* clr eot */ uptr->botf = 1; /* set bot */ } else if ((t == 03610) && sim_is_active (uptr) &&/* skip rec? */ ((mt_inst & DEV_OUT) == 0)) mt_skip = 1; /* set flag */ else CRETINS; break; case IO_DISC: /* disconnect */ sim_cancel (uptr); /* no more xfr's */ if (inst & DEV_OUT) { /* write? */ if (r = mt_wrend (inst)) /* end record */ return r; } break; case IO_WREOR: /* write eor */ chan_set_flag (mt_dib.chan, CHF_EOR); /* set eor flg */ if (r = mt_wrend (inst)) /* end record */ return r; mt_gap = 1; /* in gap */ sim_activate (uptr, mt_gtime); /* start timer */ break; case IO_SKS: /* SKS */ new_ch = I_GETSKCH (inst); /* get chan # */ if (new_ch != mt_dib.chan) /* wrong chan? */ return SCPE_IERR; if ((inst & (DEV_OUT | DEV_MTS)) == 0) { /* not sks 1n? */ t = I_GETSKCND (inst); /* get skip cond */ switch (t) { /* case sks cond */ case 001: /* sks 1021n */ *dat = 1; /* not magpak */ break; case 002: /* sks 1041n */ if (!(uptr->flags & UNIT_ATT) || /* not ready */ sim_is_active (uptr)) *dat = 1; break; case 004: /* sks 1101n */ if (!uptr->eotf) *dat = 1; /* not EOT */ break; case 010: /* sks 1201n */ if (!uptr->botf) *dat = 1; /* not BOT */ break; case 013: /* sks 12610 */ if (!mt_gap) *dat = 1; /* not in gap */ break; case 017: /* sks 13610 */ if (!mt_eof) *dat = 1; /* not EOF */ break; case 020: /* sks 1401n */ if (!sim_tape_wrp (uptr)) *dat = 1; /* not wrp */ break; case 031: /* sks 1621n */ case 033: /* sks 1661n */ *dat = 1; /* not 556bpi */ case 035: /* sks 1721n */ break; /* not 800bpi */ } } /* end if */ break; case IO_READ: /* read */ xfr_req = xfr_req & ~XFR_MT0; /* clr xfr flag */ if (mt_blnt == 0) { /* first read? */ r = mt_readrec (uptr); /* get data */ if ((r != SCPE_OK) || (mt_blnt == 0)) /* err, inv reclnt? */ return r; } uptr->botf = 0; /* off BOT */ if (mt_inst & CHC_REV) /* get next rev */ chr = mtxb[--mt_bptr] & 077; else chr = mtxb[mt_bptr++] & 077; /* get next fwd */ if (!(mt_inst & CHC_BIN)) /* bcd? */ chr = bcd_to_sds[chr]; *dat = chr & 077; /* give to chan */ if ((mt_inst & CHC_REV)? (mt_bptr <= 0): /* rev or fwd, */ (mt_bptr >= mt_blnt)) /* recd done? */ mt_readend (uptr); break; case IO_WRITE: /* write */ uptr->botf = 0; /* off BOT */ chr = (*dat) & 077; xfr_req = xfr_req & ~XFR_MT0; /* clr xfr flag */ if (!(mt_inst & CHC_BIN)) /* bcd? */ chr = sds_to_bcd[chr]; if (mt_bptr < MT_MAXFR) mtxb[mt_bptr++] = chr; /* insert in buf */ break; default: CRETINS; } return SCPE_OK; }