home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377b.lha / devices / input / inputswap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-02-03  |  4.2 KB  |  126 lines

  1. /* Copyright (c) 1990 Commodore-Amiga, Inc.
  2.  *
  3.  * This example is provided in electronic form by Commodore-Amiga, Inc. for
  4.  * use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals.
  5.  * The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  6.  * information on the correct usage of the techniques and operating system
  7.  * functions presented in this example.  The source and executable code of
  8.  * this example may only be distributed in free electronic form, via bulletin
  9.  * board or as part of a fully non-commercial and freely redistributable
  10.  * diskette.  Both the source and executable code (including comments) must
  11.  * be included, without modification, in any copy.  This example may not be
  12.  * published in printed form or distributed with any commercial product.
  13.  * However, the programming techniques and support routines set forth in
  14.  * this example may be used in the development of original executable
  15.  * software products for Commodore Amiga computers.
  16.  * All other rights reserved.
  17.  * This example is provided "as-is" and is subject to change; no warranties
  18.  * are made.  All use is at your own risk.  No liability or responsibility
  19.  * is assumed.
  20.  */
  21.  
  22. /*
  23.  * InputDevice example
  24.  *
  25.  * This example swaps the function of the left and right mouse buttons
  26.  * The C code is just the wrapper that installs and removes the
  27.  * input.device handler that does the work.
  28.  *
  29.  * The handler is written in assembly code since it is important that
  30.  * handlers be as fast as possible while processing the input events.
  31.  *
  32.  * Compile and link as follows:
  33.  *
  34.  * LC -cfirst -v -w InputSwap.c
  35.  *
  36.  * Cape assemble:
  37.  *
  38.  * Casm -a InputHandler.a -i INCLUDE: -o InputHandler.o
  39.  *
  40.  * BLink:
  41.  *
  42.  * BLink from LIB:c.o+InputSwap.o+inputhandler.o LIB LIB:lcs.lib LIB:amiga.lib TO InputSwap
  43.  *
  44.  */
  45.  
  46. #include <exec/types.h>
  47. #include <exec/memory.h>
  48. #include <devices/input.h>
  49. #include <intuition/intuition.h>
  50.  
  51. #include <proto/all.h>
  52.  
  53. UBYTE NameString[]="Button Swap";
  54.  
  55. struct NewWindow mywin={0,0,124,10,0,1,CLOSEWINDOW,
  56.                         WINDOWDRAG|WINDOWCLOSE|SIMPLE_REFRESH|NOCAREREFRESH,
  57.                         NULL,NULL,NameString,NULL,NULL,0,0,0,0,WBENCHSCREEN};
  58.  
  59. extern VOID ButtonSwap();
  60.  
  61. extern struct IntuitionBase *IntuitionBase;
  62.  
  63. /*
  64.  * This routine opens a window and waits for the one event that
  65.  * can happen (CLOSEWINDOW)  This is just to let the user play with
  66.  * the swapped buttons and then close the program...
  67.  */
  68. VOID WaitForUser(VOID)
  69. {
  70. struct Window  *win;
  71.  
  72.     if (IntuitionBase=(struct IntuitionBase *)
  73.                                     OpenLibrary("intuition.library",0L))
  74.     {
  75.         if (win=OpenWindow(&mywin))
  76.         {
  77.             WaitPort(win->UserPort);
  78.             ReplyMsg(GetMsg(win->UserPort));
  79.  
  80.             CloseWindow(win);
  81.         }
  82.         CloseLibrary((struct Library *)IntuitionBase);
  83.     }
  84. }
  85.  
  86. VOID main(VOID)
  87. {
  88. struct IOStdReq  *inputReqBlk;
  89. struct MsgPort   *inputPort;
  90. struct Interrupt *inputHandler;
  91.  
  92.     if (inputPort=CreatePort(NULL,NULL))
  93.     {
  94.         if (inputHandler=AllocMem(sizeof(struct Interrupt),
  95.                                    MEMF_PUBLIC|MEMF_CLEAR))
  96.         {
  97.             if (inputReqBlk=(struct IOStdReq *)CreateExtIO(inputPort,
  98.                                                      sizeof(struct IOStdReq)))
  99.             {
  100.                 if (!OpenDevice("input.device",NULL,
  101.                                  (struct IORequest *)inputReqBlk,NULL))
  102.                 {
  103.                     inputHandler->is_Code=ButtonSwap;
  104.                     inputHandler->is_Data=NULL;
  105.                     inputHandler->is_Node.ln_Pri=100;
  106.                     inputHandler->is_Node.ln_Name=NameString;
  107.                     inputReqBlk->io_Data=(APTR)inputHandler;
  108.                     inputReqBlk->io_Command=IND_ADDHANDLER;
  109.                     DoIO((struct IORequest *)inputReqBlk);
  110.  
  111.                     WaitForUser();
  112.  
  113.                     inputReqBlk->io_Data=(APTR)inputHandler;
  114.                     inputReqBlk->io_Command=IND_REMHANDLER;
  115.                     DoIO((struct IORequest *)inputReqBlk);
  116.  
  117.                     CloseDevice((struct IORequest *)inputReqBlk);
  118.                 }
  119.                 DeleteExtIO((struct IORequest *)inputReqBlk);
  120.             }
  121.             FreeMem(inputHandler,sizeof(struct Interrupt));
  122.         }
  123.         DeletePort(inputPort);
  124.     }
  125. }
  126.