home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / fish / libraries / input_446 / src / devicetoolkits / input / test_proto / test4.c < prev    next >
C/C++ Source or Header  |  1991-01-05  |  3KB  |  155 lines

  1. #include <stdio.h>
  2.  
  3. #include "DeviceToolKits/Input.h"
  4. #ifndef  TESTPROTO
  5. #define  NO_PRAGMAS  1
  6. #endif
  7. #include "DeviceToolKits/proto/Input.h"
  8. #include "DeviceToolKits/InputBase.h"
  9.  
  10. typedef  void  (*VoidFunc)();
  11.  
  12. DTInput_t            Unit0;
  13. struct   Interrupt   handler_setup;
  14. struct   InputEvent  event_copy;
  15. int                  found_key;
  16. int                  event_count;
  17.  
  18. #ifdef   MANX
  19. APTR                 GetA4();
  20. void                 ManxHandler();
  21.  
  22. #asm
  23.    xdef     _ManxHandler
  24.    xdef     _GetA4
  25.    xref     _ehandler
  26.  
  27. _GetA4:
  28.    move.l   a4,d0
  29.    rts
  30.  
  31. _ManxHandler:
  32.    movem.l  d2-d7/a2-a6,-(sp)
  33.    move.l   a1,a4
  34.    move.l   a0,-(sp)
  35.    jsr      _ehandler
  36.    addq.l   #4,sp
  37.    movem.l  (sp)+,d2-d7/a2-a6
  38.    rts
  39. #endasm
  40. #endif
  41.  
  42. #ifdef   SAS
  43. APTR  __saveds __asm ehandler(register __a0 struct InputEvent *events,
  44.                               register __a1 struct InputEvent *copy)
  45. #endif
  46. #ifdef   MANX
  47. APTR  ehandler(events)
  48. struct   InputEvent  *events;
  49. #endif
  50. {
  51.    register struct   InputEvent  *ep, *laste;
  52.  
  53.    event_count++;
  54.  
  55.    for (ep = events, laste = NULL; ep != NULL; ep = ep->ie_NextEvent) {
  56.       if ((ep->ie_Class == IECLASS_RAWKEY) &&
  57.          (ep->ie_Code == 0x45) &&
  58.          (ep->ie_Qualifier & IEQUALIFIER_LCOMMAND)) {
  59.          if (laste == NULL) {
  60.             events = ep->ie_NextEvent;
  61.          }
  62.          else {
  63.             laste->ie_NextEvent = ep->ie_NextEvent;
  64.          }
  65.          found_key = 1;
  66. #ifdef   SAS
  67.          *copy = *ep;
  68. #endif
  69. #ifdef   MANX
  70.          event_copy = *ep;
  71. #endif
  72.       }
  73.       else {
  74.          laste = ep;
  75.       }
  76.    }
  77.    return ((APTR) events);
  78. }
  79.  
  80. main(argc,argv)
  81. int   argc;
  82. char  *argv[];
  83. {
  84.    long  status;
  85.  
  86. #ifdef   TESTSHARED
  87. /*  Open the Input library  */
  88.  
  89.    DTInputOpen(DTINPUTREV);
  90. #endif
  91.  
  92. /*  Try to initialize unit 0 of the Input  */
  93.  
  94.    if ((Unit0 = DTInputCreate(&status)) == NULL) {
  95.       fprintf(stderr,"Error initializing unit 0 = %ld.\n",status);
  96.       fflush(stderr);
  97.       goto cleanup;
  98.    }
  99.  
  100. /*  Initialze the input event handler  */
  101.  
  102.    found_key = 0;
  103.    event_count = 0;
  104.    handler_setup.is_Node.ln_Pri = 51;
  105. #ifdef   SAS
  106.    handler_setup.is_Code = (VoidFunc) ehandler;
  107.    handler_setup.is_Data = (APTR) &event_copy;
  108. #endif
  109. #ifdef   MANX
  110.    handler_setup.is_Code = (VoidFunc) ManxHandler;
  111.    handler_setup.is_Data = (APTR) GetA4();
  112. #endif
  113.  
  114.    printf("Press <Left-Amiga Escape> to exit.\n");
  115.  
  116. /*  Set up the input event handler  */
  117.  
  118.    if ((status = DTInputAddHandler(Unit0,&handler_setup)) != 0) {
  119.       fprintf(stderr,"Error adding handler = %ld,%ld.\n",
  120.                status,Unit0->in_error);
  121.       fflush(stderr);
  122.       goto cleanup;
  123.    }
  124.  
  125. /*  Wait for the LeftAmiga-Escape sequence to be pressed  */
  126.  
  127.    while (TRUE) {
  128.       if (found_key) {
  129.          break;
  130.       }
  131.       Delay(15L);
  132.    }
  133.  
  134.    printf("Key sequence hit.\n");
  135.    fflush(stdout);
  136.  
  137. /*  Remove up the input event handler  */
  138.  
  139.    if ((status = DTInputRemHandler(Unit0,&handler_setup)) != 0) {
  140.       fprintf(stderr,"Error removing handler = %ld,%ld.\n",
  141.                status,Unit0->in_error);
  142.       fflush(stderr);
  143.       goto cleanup;
  144.    }
  145.  
  146. /*  Free the stuff  */
  147.  
  148. cleanup:
  149.    DTInputFree(Unit0);
  150. #ifdef   TESTSHARED
  151.    DTInputClose();
  152. #endif
  153. }
  154.  
  155.