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

  1. /* pdp8_tt.c: PDP-8 console terminal simulator
  2.  
  3.    Copyright (c) 1993, 1994, Robert M Supnik, Digital Equipment Corporation
  4.    Commercial use prohibited
  5.  
  6.    tti        terminal input
  7.    tto        terminal output
  8. */
  9.  
  10. #include "pdp8_defs.h"
  11.  
  12. extern int int_req, dev_done, dev_enable, stop_inst;
  13. int tti_svc (UNIT *uptr);
  14. int tto_svc (UNIT *uptr);
  15. int tti_reset (DEVICE *dptr);
  16. int tto_reset (DEVICE *dptr);
  17. extern int sim_activate (UNIT *uptr, int interval);
  18. extern int sim_cancel (UNIT *uptr);
  19. extern int sim_poll_kbd (void);
  20. extern int sim_type_tty (char out);
  21.  
  22. /* TTI data structures
  23.  
  24.    tti_dev    TTI device descriptor
  25.    tti_unit    TTI unit descriptor
  26.    tti_reg    TTI register list
  27. */
  28.  
  29. UNIT tti_unit = { UDATA (&tti_svc, 0, 0), KBD_POLL_WAIT };
  30.  
  31. REG tti_reg[] = {
  32.     { ORDATA (BUF, tti_unit.buf, 8) },
  33.     { FLDATA (DONE, dev_done, INT_V_TTI) },
  34.     { FLDATA (ENABLE, dev_enable, INT_V_TTI) },
  35.     { FLDATA (INT, int_req, INT_V_TTI) },
  36.     { DRDATA (POS, tti_unit.pos, 32), PV_LEFT },
  37.     { DRDATA (TIME, tti_unit.wait, 24), REG_NZ + PV_LEFT },
  38.     { NULL }  };
  39.  
  40. DEVICE tti_dev = {
  41.     "TTI", &tti_unit, tti_reg, NULL,
  42.     1, 10, 32, 1, 8, 8,
  43.     NULL, NULL, &tti_reset,
  44.     NULL, NULL, NULL };
  45.  
  46. /* TTO data structures
  47.  
  48.    tto_dev    TTO device descriptor
  49.    tto_unit    TTO unit descriptor
  50.    tto_reg    TTO register list
  51. */
  52.  
  53. UNIT tto_unit = { UDATA (&tto_svc, 0, 0), SERIAL_OUT_WAIT };
  54.  
  55. REG tto_reg[] = {
  56.     { ORDATA (BUF, tto_unit.buf, 8) },
  57.     { FLDATA (DONE, dev_done, INT_V_TTO) },
  58.     { FLDATA (ENABLE, dev_enable, INT_V_TTO) },
  59.     { FLDATA (INT, int_req, INT_V_TTO) },
  60.     { DRDATA (POS, tto_unit.pos, 32), PV_LEFT },
  61.     { DRDATA (TIME, tto_unit.wait, 24), PV_LEFT },
  62.     { NULL }  };
  63.  
  64. DEVICE tto_dev = {
  65.     "TTO", &tto_unit, tto_reg, NULL,
  66.     1, 10, 32, 1, 8, 8,
  67.     NULL, NULL, &tto_reset, 
  68.     NULL, NULL, NULL };
  69.  
  70. /* Terminal input: IOT routine */
  71.  
  72. int tti (int pulse, int AC)
  73. {
  74. switch (pulse) {                    /* decode IR<9:11> */
  75. case 0:                         /* KCF */
  76.     dev_done = dev_done & ~INT_TTI;            /* clear flag */
  77.     int_req = int_req & ~INT_TTI;
  78.     return AC;
  79. case 1:                            /* KSF */
  80.     return (dev_done & INT_TTI)? IOT_SKP + AC: AC;
  81. case 2:                            /* KCC */
  82.     dev_done = dev_done & ~INT_TTI;            /* clear flag */
  83.     int_req = int_req & ~INT_TTI;
  84.     return 0;                    /* clear AC */
  85. case 4:                            /* KRS */
  86.     return (AC | tti_unit.buf);            /* return buffer */
  87. case 5:                            /* KIE */
  88.     if (AC & 1) dev_enable = dev_enable | (INT_TTI+INT_TTO);
  89.     else dev_enable = dev_enable & ~(INT_TTI+INT_TTO);
  90.     int_req = INT_UPDATE;                /* update interrupts */
  91.     return AC;
  92. case 6:                            /* KRB */
  93.     dev_done = dev_done & ~INT_TTI;            /* clear flag */
  94.     int_req = int_req & ~INT_TTI;
  95.     return (tti_unit.buf);                /* return buffer */
  96. default:
  97.     return (stop_inst << IOT_V_REASON) + AC;  }    /* end switch */
  98. }
  99.  
  100. /* Unit service */
  101.  
  102. int tti_svc (UNIT *uptr)
  103. {
  104. int temp;
  105.  
  106. sim_activate (&tti_unit, tti_unit.wait);        /* continue poll */
  107. if ((temp = sim_poll_kbd ()) < SCPE_KFLAG) return temp;    /* no char or error? */
  108. tti_unit.buf = (temp & 0377) | 0200;            /* got char */
  109. dev_done = dev_done | INT_TTI;                /* set done */
  110. int_req = INT_UPDATE;                    /* update interrupts */
  111. tti_unit.pos = tti_unit.pos + 1;
  112. return SCPE_OK;
  113. }
  114.  
  115. /* Reset routine */
  116.  
  117. int tti_reset (DEVICE *dptr)
  118. {
  119. tti_unit.buf = 0;
  120. dev_done = dev_done & ~INT_TTI;                /* clear done, int */
  121. int_req = int_req & ~INT_TTI;
  122. dev_enable = dev_enable | INT_TTI;            /* set enable */
  123. sim_activate (&tti_unit, tti_unit.wait);        /* activate unit */
  124. return SCPE_OK;
  125. }
  126.  
  127. /* Terminal output: IOT routine */
  128.  
  129. int tto (int pulse, int AC)
  130. {
  131. switch (pulse) {                    /* decode IR<9:11> */
  132. case 0:                         /* TLF */
  133.     dev_done = dev_done | INT_TTO;            /* set flag */
  134.     int_req = INT_UPDATE;                /* update interrupts */
  135.     return AC;
  136. case 1:                            /* TSF */
  137.     return (dev_done & INT_TTO)? IOT_SKP + AC: AC;
  138. case 2:                            /* TCF */
  139.     dev_done = dev_done & ~INT_TTO;            /* clear flag */
  140.     int_req = int_req & ~INT_TTO;            /* clear int req */
  141.     return AC;
  142. case 5:                            /* SPI */
  143.     return (int_req & (INT_TTI+INT_TTO))? IOT_SKP + AC: AC;
  144. case 6:                            /* TLS */
  145.     dev_done = dev_done & ~INT_TTO;            /* clear flag */
  146.     int_req = int_req & ~INT_TTO;            /* clear int req */
  147. case 4:                            /* TPC */
  148.     sim_activate (&tto_unit, tto_unit.wait);    /* activate unit */
  149.     tto_unit.buf = AC;                /* load buffer */
  150.     return AC;
  151. default:
  152.     return (stop_inst << IOT_V_REASON) + AC;  }    /* end switch */
  153. }
  154.  
  155. /* Unit service */
  156.  
  157. int tto_svc (UNIT *uptr)
  158. {
  159. int temp;
  160.  
  161. dev_done = dev_done | INT_TTO;                /* set done */
  162. int_req = INT_UPDATE;                    /* update interrupts */
  163. if ((temp = sim_type_tty (tto_unit.buf & 0177)) != SCPE_OK) return temp;
  164. tto_unit.pos = tto_unit.pos + 1;
  165. return SCPE_OK;
  166. }
  167.  
  168. /* Reset routine */
  169.  
  170. int tto_reset (DEVICE *dptr)
  171. {
  172. tto_unit.buf = 0;
  173. dev_done = dev_done & ~INT_TTO;                /* clear done, int */
  174. int_req = int_req & ~INT_TTO;
  175. dev_enable = dev_enable | INT_TTO;            /* set enable */
  176. sim_cancel (&tto_unit);                    /* deactivate unit */
  177. return SCPE_OK;
  178. }
  179.