home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_12 / 8n12088a < prev    next >
Text File  |  1990-08-29  |  2KB  |  68 lines

  1. /* kclient.c - Keyboard Client Task */
  2.  
  3. #include <synrtx.h>
  4.  
  5. #define REL   (((word)0x0100) | ((word)'r'))
  6.  
  7. /* handler numbers */
  8. #define GRANT    0
  9. #define GETCHAR  1
  10.  
  11. static word character;
  12.  
  13. static handler Grant(msg_t *msg_p) { /* for synchronization only */
  14. }
  15.  
  16. static handler GetChar(msg_t *msg_p) {
  17.     character = msg_p->value.w;
  18. }
  19.  
  20. task KeyboardClient(void) {
  21.     register task_t self  = task_self();
  22.     register task_t ksTid = task_idOf("KeyboardServer");
  23.     msg_t msg;
  24.     
  25.     task_setHandler(2, Grant, GetChar);
  26.  
  27.     loop {
  28.         /* interrupt KeyboardServer.Acquire, then wait on Grant */
  29.         msg.srcTid = self;
  30.         msg.dstTid = ksTid;
  31.         msg.dstHid = 0; /* Acquire = 0 */
  32.         msg.type   = msg_type_SYNC;
  33.         task_interruptEnableWait(&msg, NO_TIMEOUT, 1, GRANT);
  34.         io_puts("\nKeyboardClient: Acquired\n");
  35.         character = 0;
  36.         loop {
  37.             /* interrupt if KeyboardServer.Hit and wait for GetChar */
  38.             msg.srcTid = self;
  39.             msg.dstTid = ksTid;
  40.             msg.dstHid = 2; /* Hit = 2 */
  41.             msg.type   = msg_type_SYNC;
  42.             task_interruptEnableWait(&msg, NO_TIMEOUT, 1, GETCHAR);
  43.             /* 
  44.              * a legal character is a word 0x01xx where "xx" (LSB) is the
  45.              * actual character.  The character 0x0000 means no key hit.
  46.              */
  47.             if (character) {
  48.                 io_putc((char)character);
  49.                 if (character == REL) break; /* then 'r'elease */
  50.                 character = 0;
  51.             }
  52.         }
  53.  
  54.         /* interrupt KeyboardServer.Release */
  55.         msg.srcTid = self;
  56.         msg.dstTid = ksTid;
  57.         msg.dstHid = 1; /* Release = 1 */
  58.         msg.type   = msg_type_SYNC;
  59.         task_interrupt(&msg);
  60.         io_puts("\nKeyboardClient: Released and delayed for 10 secs ...\n");
  61.         /*
  62.          * 10 seconds of freedom for the keyboard. All the characters typed
  63.          * during that time will flushed at the time of next Acquirement.
  64.          */
  65.         task_delay(500L);
  66.     }
  67. }
  68.