home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / commodities / superdark / main / input.c < prev    next >
C/C++ Source or Header  |  1993-02-27  |  7KB  |  235 lines

  1. /************************************************************************/
  2. /*                                    */
  3. /*    File input.c                            */
  4. /*                                    */
  5. /************************************************************************/
  6. /*                                     */
  7. /*                                    */
  8. /*                                    */
  9. /************************************************************************/
  10.  
  11. #include <exec/types.h>
  12. #include <dos/dos.h>
  13. #include <exec/interrupts.h>
  14. #include <devices/input.h>
  15. #include <devices/inputevent.h>
  16. #include <intuition/intuition.h>
  17. #include <intuition/intuitionbase.h>
  18. #include <graphics/view.h>
  19. #include <libraries/dos.h>
  20. #include <libraries/dosextens.h>
  21. #include "/includes/struct.h"
  22.  
  23. #define reg register
  24. #define    NOK    1
  25. #define    OK    0
  26.  
  27. #define    ABS(x)    (x<0?x:-x)
  28.  
  29. struct my_data    my_info;
  30. struct    MsgPort *port = NULL;
  31. UBYTE    inputopen = -1;
  32. struct    IOStdReq *inputreq = NULL;
  33. struct Interrupt myhandler;        /* input handler */
  34. long    lsec=0;
  35.  
  36. extern    struct    Library    *IntuitionBase;
  37.  
  38. /**********************************************************/
  39. /* This is the input event handler.             */
  40. /**********************************************************/
  41.  
  42. struct InputEvent * __saveds __asm myproc_Handler
  43.             (reg __a0 struct InputEvent *ev,reg __a1 struct my_data *info)
  44. {
  45.     struct InputEvent *inev;
  46.     static    int    waiting=0;
  47.  
  48.     inev = ev;
  49.     while (ev) {
  50.  
  51.         /* Ici, c'est le test pour l'envoi d'un signal de reactivation    */
  52.         /* de la fenetre, si on recoit shift gauche+f3            */
  53.  
  54.           if ((ev->ie_Class == IECLASS_RAWKEY)&&
  55.         (ev->ie_Code==0x52)&&
  56.         ((ev->ie_Qualifier&IEQUALIFIER_LSHIFT)==IEQUALIFIER_LSHIFT)){
  57.             Signal(info->task,1<<info->sigshow);
  58.             inev=ev->ie_NextEvent;
  59.         }
  60.  
  61.  
  62.  
  63.         /* Si on recoit une demande d'immediate blanking    */
  64.  
  65.           if ((ev->ie_Class == IECLASS_RAWKEY)&&
  66.         (ev->ie_Code==0x53)&&
  67.         ((ev->ie_Qualifier&IEQUALIFIER_LSHIFT)==IEQUALIFIER_LSHIFT)){
  68.             if(info->flg_stop==0){
  69.                 Signal(info->task,1<<info->sigstart);
  70.                 inev=ev->ie_NextEvent;
  71.                 waiting=my_info.tempo+1;
  72.             }
  73.         }
  74.         /* Si il y a mvt de la souris ou frappe de touche, on remet la    */
  75.         /* tempo a 0. Si de plus, on avait envoyer un signal de blank    */
  76.         /* et bien on renvoi un signal de chgt                */
  77.  
  78.           if ((ev->ie_Class == IECLASS_RAWKEY) || (ev->ie_Class == IECLASS_RAWMOUSE)){
  79.             if(info->flg_stop==1){
  80.                 if(my_info.flg_send==1){
  81.                    Signal(info->task,1<<info->sigstop);
  82.                 }
  83.             }
  84.             waiting = 0;
  85.         }
  86.  
  87.         /* Evenement timer, sert a compter la non activitee du clavier */
  88.  
  89.         if ((ev->ie_Class == IECLASS_TIMER)){
  90.  
  91.             register struct IntuitionBase *ib =(struct IntuitionBase *) IntuitionBase;
  92.             register short  mousey;
  93.             register struct    Screen *scr = ib->FirstScreen;
  94.  
  95.               if ((ev->ie_TimeStamp.tv_secs != lsec)) {
  96.             lsec = ev->ie_TimeStamp.tv_secs;
  97.  
  98.             /* Si on est en mode aleatoire */
  99.             if(my_info.flg_alea==TRUE){
  100.                     if(waiting<my_info.tempo_end+1+my_info.tempo)
  101.                     waiting = waiting + 1;
  102.             }else{
  103.                     if(waiting<my_info.tempo+1)
  104.                     waiting = waiting + 1;
  105.             }
  106.             my_info.debug1=waiting;
  107.                   }
  108.  
  109.              /* Si coin inferieur gauche, blanking immediat, mais */
  110.              /* seuleument si la souri n'a pas bouge depuis plus  */
  111.              /* de 3 secondes                      */
  112.              my_info.debug2=ib->MouseY;
  113.              if (waiting==2){
  114.  
  115.             mousey = ib->MouseY;
  116.             if (!(scr->ViewPort.Modes & LACE)){
  117.                 mousey >>=1;
  118.             }
  119.             my_info.debug2=scr->Height-mousey;
  120.             if(    (scr->Height-mousey<4)){
  121.                 if(ib->MouseX<2){
  122.                     if(info->flg_stop==0){
  123.                         Signal(info->task,1<<info->sigstart);
  124.                         waiting=my_info.tempo+1;
  125.                     }
  126.                 }
  127.                 /* Si coin inferieur droit...pas de blank */
  128.                 if(scr->Width -ib->MouseX<2){
  129.                     waiting=0;
  130.                 }
  131.               }
  132.              }
  133.  
  134.         }
  135.         ev = ev->ie_NextEvent;
  136.     }
  137.     if(my_info.flg_send==1){
  138.  
  139.         /********************************************************/
  140.         /* Si il n'y a pas eu d'activitee depuis belle lurette    */
  141.         /* on declenche une tempo de non activitee        */
  142.         /********************************************************/
  143.         
  144.         if((waiting==my_info.tempo)&&(info->flg_stop==0)){
  145.             Signal(info->task,1<<info->sigstart);
  146.             waiting++;
  147.         }
  148.     
  149.         /********************************************************/
  150.         /* Si on arrive a la fin de la deuxieme temporisation,    */
  151.         /* on indique qu'il faut  arreter l'effet en cours    */
  152.         /* mais on remet la tempo juste avant la valeur maximum    */
  153.         /* de non activitee, pour que tout de suite un autre     */
  154.         /* effet soit lance (Mode "aleatoire")            */
  155.         /********************************************************/
  156.         if((waiting==my_info.tempo_end+my_info.tempo)&&(info->flg_alea==TRUE)){
  157.                 Signal(info->task,1<<my_info.signext);
  158.             waiting = my_info.tempo+1;
  159.         }
  160.     }
  161.     return (inev);
  162. }
  163.  
  164. /********************************************************/
  165. /* This is the initialisation of my input event handler */
  166. /********************************************************/
  167.  
  168. int    init_input_ev()
  169. {
  170.     port=(struct MsgPort *)CreatePort ("p", 0L);
  171.     my_info.flg_stop=0;
  172.     my_info.flg_send=1;
  173.     my_info.sigshow=AllocSignal(-1);
  174.     if(my_info.sigshow==-1){
  175.         printf("allocsignal show failed\n");
  176.         return(TRUE);
  177.     }
  178.     my_info.sigstart=AllocSignal(-1);
  179.     if(my_info.sigstart==-1){
  180.         printf("allocsignal failed\n");
  181.         return(TRUE);
  182.     }
  183.     my_info.sigstop=AllocSignal(-1);
  184.     if(my_info.sigstop==-1){
  185.         printf("allocsignal failed\n");
  186.         return(TRUE);
  187.     }
  188.     my_info.signext=AllocSignal(-1);
  189.     if(my_info.signext==-1){
  190.         printf("allocsignal failed\n");
  191.         return(TRUE);
  192.     }
  193.     my_info.task=(struct Task *)FindTask(0);
  194.  
  195.     if ( (inputreq = (struct IOStdreq *)CreateStdIO (port)) ==NULL){
  196.         printf("stdio failed\n");
  197.         return(TRUE);
  198.     }
  199.     inputopen = OpenDevice ("input.device", 0L, inputreq, 0L);
  200.     if ( inputopen !=0 ){
  201.         printf("open device failed\n");
  202.         return(TRUE);
  203.     }
  204.  
  205.     myhandler.is_Code = (void (*)())myproc_Handler;
  206.     myhandler.is_Data =(APTR)&my_info;
  207.     myhandler.is_Node.ln_Pri = 51;
  208.     inputreq->io_Command = IND_ADDHANDLER;
  209.     inputreq->io_Data =(APTR) &myhandler;
  210.     DoIO (inputreq);
  211.  
  212.     return(FALSE);
  213. }
  214.  
  215. /******************************************************************/
  216. /* This is the liberation of the previously allocated ressources  */
  217. /* of the input event                          */
  218. /******************************************************************/
  219.  
  220. void    free_input_ev()
  221. {
  222.     if(inputreq){
  223.         inputreq->io_Command = IND_REMHANDLER;
  224.         inputreq->io_Data = (APTR)&myhandler;
  225.         DoIO (inputreq);
  226.     }
  227.     if (!inputopen) CloseDevice (inputreq);
  228.     if(inputreq)DeleteStdIO (inputreq);
  229.     if(my_info.signext!=-1)FreeSignal(my_info.signext);
  230.     if(my_info.sigstart!=-1)FreeSignal(my_info.sigstart);
  231.     if(my_info.sigshow!=-1)FreeSignal(my_info.sigshow);
  232.     if(my_info.sigstop!=-1)FreeSignal(my_info.sigstop);
  233.         if (port) DeletePort (port);
  234.