home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk416.lzh / Intoxicated / source / main.c < prev    next >
C/C++ Source or Header  |  1990-12-16  |  2KB  |  97 lines

  1. #include <exec/types.h>
  2. #include <devices/input.h>
  3. #include <exec/execbase.h>
  4. #include <exec/interrupts.h>
  5. #include <exec/io.h>
  6. #include <proto/exec.h>
  7. #include <proto/intuition.h>
  8.  
  9. long _stack = 4000;
  10. char *_procname = "Intoxicated";
  11. long _priority = 0;
  12. long _BackGroundIO = 0;
  13.  
  14. extern struct ExecBase *SysBase;
  15. struct IntuitionBase *IntuitionBase;
  16.  
  17. struct MsgPort *InputPort;
  18. struct IOStdReq *InputReq;
  19. struct Interrupt Handler;
  20.  
  21. extern struct MsgPort *CreatePort();
  22. extern void DeletePort();
  23. extern struct IOStdReq *CreateStdIO();
  24. extern void DeleteStdIO();
  25.  
  26. extern struct InputEvent *MHandler();
  27.  
  28. struct
  29. {
  30.     struct Task *TaskAddr;
  31.     BYTE Signal;
  32. } Common;
  33.  
  34.  
  35. int CXBRK()
  36.  
  37. {
  38.     return(0);
  39. }
  40.  
  41.  
  42. void OpenAll()
  43.  
  44. {
  45.     void CloseAll();
  46.     
  47.     if (!(IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",0L)))  CloseAll();
  48.     
  49.     if ((Common.Signal = AllocSignal(-1L)) == -1)  CloseAll();
  50.     Common.TaskAddr = SysBase->ThisTask;
  51.     
  52.     if (!(InputPort = CreatePort(NULL,0)))  CloseAll();
  53.     if (!(InputReq = CreateStdIO(InputPort)))  CloseAll();
  54.     if (OpenDevice("input.device",0,(struct IORequest *) InputReq,0))  CloseAll();
  55.     Handler.is_Node.ln_Pri = 51;
  56.     Handler.is_Node.ln_Name = "BrokenMouse_Input_Handler";
  57.     Handler.is_Code = (void (*)) MHandler;
  58.     InputReq->io_Command = IND_ADDHANDLER;
  59.     InputReq->io_Data = (APTR) &Handler;
  60.     SendIO((struct IORequest *) InputReq);
  61. }
  62.  
  63.  
  64. void CloseAll()
  65.  
  66. {
  67.     if (InputReq->io_Command)
  68.     {
  69.         InputReq->io_Command = IND_REMHANDLER;
  70.         InputReq->io_Data = (APTR) &Handler;
  71.         DoIO((struct IORequest *) InputReq);
  72.         CloseDevice((struct IORequest *) InputReq);
  73.     };
  74.     if (InputReq) DeleteStdIO(InputReq);
  75.     if (InputPort) DeletePort(InputPort);
  76.     
  77.     if (Common.Signal)  FreeSignal(Common.Signal);
  78.     
  79.     if (IntuitionBase)  CloseLibrary((struct Library *) IntuitionBase);
  80.     
  81.     exit(0);
  82. }
  83.  
  84.  
  85. void _main()
  86.  
  87. {
  88.     OpenAll();
  89.     DisplayBeep(NULL);
  90.     
  91.     Wait(1 << Common.Signal);
  92.     
  93.     DisplayBeep(NULL);
  94.     CloseAll();    
  95. }
  96.  
  97.