home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Boot_Images / 2.11_on_rl02 / pdpsim.tz / pdpsim / pdp11_lp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-29  |  3.4 KB  |  128 lines

  1. /* pdp11_lp.c: PDP-11 line printer simulator
  2.  
  3.    Copyright (c) 1993, 1994, Robert M Supnik, Digital Equipment Corporation
  4.    Commercial use prohibited
  5.  
  6.    lpt        line printer
  7. */
  8.  
  9. #include "pdp11_defs.h"
  10.  
  11. #define LPTCSR_IMP    (CSR_ERR + CSR_DONE + CSR_IE)    /* implemented */
  12. #define LPTCSR_RW    (CSR_IE)            /* read/write */
  13.  
  14. extern int int_req;
  15. int lpt_csr = 0;                    /* control/status */
  16. int lpt_stopioe = 0;                    /* stop on error */
  17. int lpt_svc (UNIT *uptr);
  18. int lpt_reset (DEVICE *dptr);
  19. int lpt_attach (UNIT *uptr, char *ptr);
  20. int lpt_detach (UNIT *uptr);
  21. extern int sim_activate (UNIT *uptr, int interval);
  22. extern int sim_cancel (UNIT *uptr);
  23. extern int attach_unit (UNIT *uptr, char *cptr);
  24. extern int detach_unit (UNIT *uptr);
  25.  
  26. /* LPT data structures
  27.  
  28.    lpt_dev    LPT device descriptor
  29.    lpt_unit    LPT unit descriptor
  30.    lpt_reg    LPT register list
  31. */
  32.  
  33. UNIT lpt_unit = {
  34.     UDATA (&lpt_svc, UNIT_SEQ+UNIT_ATTABLE, 0), SERIAL_OUT_WAIT };
  35.  
  36. REG lpt_reg[] = {
  37.     { ORDATA (LPCS, lpt_csr, 16) },
  38.     { ORDATA (LPB, lpt_unit.buf, 8) },
  39.     { FLDATA (INT, int_req, INT_V_LPT) },
  40.     { FLDATA (ERR, lpt_csr, CSR_V_ERR) },
  41.     { FLDATA (DONE, lpt_csr, CSR_V_DONE) },
  42.     { FLDATA (IE, lpt_csr, CSR_V_IE) },
  43.     { DRDATA (POS, lpt_unit.pos, 32), PV_LEFT },
  44.     { DRDATA (TIME, lpt_unit.wait, 24), PV_LEFT },
  45.     { FLDATA (STOP_IOE, lpt_stopioe, 0) },
  46.     { NULL }  };
  47.  
  48. DEVICE lpt_dev = {
  49.     "LPT", &lpt_unit, lpt_reg, NULL,
  50.     1, 10, 32, 1, 8, 8,
  51.     NULL, NULL, &lpt_reset,
  52.     NULL, &lpt_attach, &lpt_detach };
  53.  
  54. /* Line printer routines
  55.  
  56.    lpt_rd    I/O page read
  57.    lpt_wr    I/O page write
  58.    lpt_svc    process event (printer ready)
  59.    lpt_reset    process reset
  60.    lpt_attach    process attach
  61.    lpt_detach    process detach
  62. */
  63.  
  64. int lpt_rd (int *data, int PA, int access)
  65. {
  66. if ((PA & 02) == 0) *data = lpt_csr & LPTCSR_IMP;    /* csr */
  67. else *data = lpt_unit.buf;                /* buffer */
  68. return SCPE_OK;
  69. }                            /* end lpt_rd */
  70.  
  71. int lpt_wr (int data, int PA, int access)
  72. {
  73. if ((PA & 02) == 0) {                    /* csr */
  74.     if (PA & 1) return SCPE_OK;
  75.     if ((data & CSR_IE) == 0) int_req = int_req & ~INT_LPT;
  76.     else if ((lpt_csr & (CSR_DONE + CSR_IE)) == CSR_DONE)
  77.         int_req = int_req | INT_LPT;
  78.     lpt_csr = (lpt_csr & ~LPTCSR_RW) | (data & LPTCSR_RW);  }
  79. else {    if ((PA & 1) == 0) lpt_unit.buf = data & 0177;    /* buffer */
  80.     lpt_csr = lpt_csr & ~CSR_DONE;
  81.     int_req = int_req & ~INT_LPT;
  82.     if ((lpt_unit.buf == 015) || (lpt_unit.buf == 014) ||
  83.         (lpt_unit.buf == 012)) sim_activate (&lpt_unit, lpt_unit.wait);
  84.     else sim_activate (&lpt_unit, 0);  }
  85. return SCPE_OK;
  86. }                            /* end lpt_wr */
  87.  
  88. int lpt_svc (UNIT *uptr)
  89. {
  90. lpt_csr = lpt_csr | CSR_ERR | CSR_DONE;
  91. if (lpt_csr & CSR_IE) int_req = int_req | INT_LPT;
  92. if ((lpt_unit.flags & UNIT_ATT) == 0)
  93.     return IORETURN (lpt_stopioe, SCPE_UNATT);
  94. if (putc (lpt_unit.buf & 0177, lpt_unit.fileref) == EOF) {
  95.     perror ("LPT I/O error");
  96.     clearerr (lpt_unit.fileref);
  97.     return SCPE_IOERR;  }
  98. lpt_csr = lpt_csr & ~CSR_ERR;
  99. lpt_unit.pos = lpt_unit.pos + 1;
  100. return SCPE_OK;
  101. }                            /* end lpt_svc */
  102.  
  103. int lpt_reset (DEVICE *dptr)
  104. {
  105. lpt_unit.buf = 0;
  106. lpt_csr = CSR_DONE;
  107. if ((lpt_unit.flags & UNIT_ATT) == 0) lpt_csr = lpt_csr | CSR_ERR;
  108. int_req = int_req & ~INT_LPT;
  109. sim_cancel (&lpt_unit);                    /* deactivate unit */
  110. return SCPE_OK;
  111. }                            /* end lpt_reset */
  112.  
  113. int lpt_attach (UNIT *uptr, char *cptr)
  114. {
  115. int reason;
  116.  
  117. lpt_csr = lpt_csr & ~CSR_ERR;
  118. reason = attach_unit (uptr, cptr);
  119. if ((lpt_unit.flags & UNIT_ATT) == 0) lpt_csr = lpt_csr | CSR_ERR;
  120. return reason;
  121. }
  122.  
  123. int lpt_detach (UNIT *uptr)
  124. {
  125. lpt_csr = lpt_csr | CSR_ERR;
  126. return detach_unit (uptr);
  127. }
  128.