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

  1. /* nova_lp.c: NOVA line printer simulator
  2.  
  3.    Copyright (c) 1993, 1994, 1995,
  4.    Robert M Supnik, Digital Equipment Corporation
  5.    Commercial use prohibited
  6.  
  7.    lpt        line printer
  8. */
  9.  
  10. #include "nova_defs.h"
  11.  
  12. extern int int_req, dev_busy, dev_done, dev_disable;
  13. int lpt_stopioe = 0;                    /* stop on error */
  14. int lpt_svc (UNIT *uptr);
  15. int lpt_reset (DEVICE *dptr);
  16. extern int sim_activate (UNIT *uptr, int interval);
  17. extern int sim_cancel (UNIT *uptr);
  18.  
  19. /* LPT data structures
  20.  
  21.    lpt_dev    LPT device descriptor
  22.    lpt_unit    LPT unit descriptor
  23.    lpt_reg    LPT register list
  24. */
  25.  
  26. UNIT lpt_unit = {
  27.     UDATA (&lpt_svc, UNIT_SEQ+UNIT_ATTABLE, 0), SERIAL_OUT_WAIT };
  28.  
  29. REG lpt_reg[] = {
  30.     { ORDATA (BUF, lpt_unit.buf, 8) },
  31.     { FLDATA (BUSY, dev_busy, INT_V_LPT) },
  32.     { FLDATA (DONE, dev_done, INT_V_LPT) },
  33.     { FLDATA (DISABLE, dev_disable, INT_V_LPT) },
  34.     { FLDATA (INT, int_req, INT_V_LPT) },
  35.     { DRDATA (POS, lpt_unit.pos, 32), PV_LEFT },
  36.     { DRDATA (TIME, lpt_unit.wait, 24), PV_LEFT },
  37.     { FLDATA (STOP_IOE, lpt_stopioe, 0) },
  38.     { NULL }  };
  39.  
  40. DEVICE lpt_dev = {
  41.     "LPT", &lpt_unit, lpt_reg, NULL,
  42.     1, 10, 32, 1, 8, 8,
  43.     NULL, NULL, &lpt_reset,
  44.     NULL, NULL, NULL };
  45.  
  46. /* IOT routine */
  47.  
  48. int lpt (int pulse, int code, int AC)
  49. {
  50.  
  51. if (code == ioDOA) lpt_unit.buf = AC & 0177;
  52. switch (pulse) {                    /* decode IR<8:9> */
  53. case iopS:                         /* start */
  54.     dev_busy = dev_busy | INT_LPT;            /* set busy */
  55.     dev_done = dev_done & ~INT_LPT;            /* clear done, int */
  56.     int_req = int_req & ~INT_LPT;
  57.     if ((lpt_unit.buf != 015) && (lpt_unit.buf != 014) &&
  58.         (lpt_unit.buf != 012))
  59.         return (lpt_svc (&lpt_unit) << IOT_V_REASON);
  60.     sim_activate (&lpt_unit, lpt_unit.wait);
  61.     break;
  62. case iopC:                        /* clear */
  63.     dev_busy = dev_busy & ~INT_LPT;            /* clear busy */
  64.     dev_done = dev_done & ~INT_LPT;            /* clear done, int */
  65.     int_req = int_req & ~INT_LPT;
  66.     sim_cancel (&lpt_unit);                /* deactivate unit */
  67.     break;  }                    /* end switch */
  68. return 0;
  69. }
  70.  
  71. /* Unit service */
  72.  
  73. int lpt_svc (UNIT *uptr)
  74. {
  75. dev_busy = dev_busy & ~INT_LPT;                /* clear busy */
  76. dev_done = dev_done | INT_LPT;                /* set done */
  77. int_req = (int_req & ~INT_DEV) | (dev_done & ~dev_disable);
  78. if ((lpt_unit.flags & UNIT_ATT) == 0)            /* attached? */
  79.     return IORETURN (lpt_stopioe, SCPE_UNATT);
  80. if (putc (lpt_unit.buf, lpt_unit.fileref) == EOF) {
  81.     perror ("LPT I/O error");
  82.     clearerr (lpt_unit.fileref);
  83.     return SCPE_IOERR;  }
  84. lpt_unit.pos = lpt_unit.pos + 1;
  85. return SCPE_OK;
  86. }
  87.  
  88. /* Reset routine */
  89.  
  90. int lpt_reset (DEVICE *dptr)
  91. {
  92. lpt_unit.buf = 0;
  93. dev_busy = dev_busy & ~INT_LPT;                /* clear busy */
  94. dev_done = dev_done & ~INT_LPT;                /* clear done, int */
  95. int_req = int_req & ~INT_LPT;
  96. sim_cancel (&lpt_unit);                    /* deactivate unit */
  97. return SCPE_OK;
  98. }
  99.