home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / c / rkrm / input / swap_buttons.c < prev   
C/C++ Source or Header  |  1992-09-03  |  5KB  |  156 lines

  1. /*
  2.  * Copyright (c) 1992 Commodore-Amiga, Inc.
  3.  * 
  4.  * This example is provided in electronic form by Commodore-Amiga, Inc. for 
  5.  * use with the "Amiga ROM Kernel Reference Manual: Devices", 3rd Edition, 
  6.  * published by Addison-Wesley (ISBN 0-201-56775-X).
  7.  * 
  8.  * The "Amiga ROM Kernel Reference Manual: Devices" contains additional 
  9.  * information on the correct usage of the techniques and operating system 
  10.  * functions presented in these examples.  The source and executable code 
  11.  * of these examples may only be distributed in free electronic form, via 
  12.  * bulletin board or as part of a fully non-commercial and freely 
  13.  * redistributable diskette.  Both the source and executable code (including 
  14.  * comments) must be included, without modification, in any copy.  This 
  15.  * example may not be published in printed form or distributed with any
  16.  * commercial product.  However, the programming techniques and support
  17.  * routines set forth in these examples may be used in the development
  18.  * of original executable software products for Commodore Amiga computers.
  19.  * 
  20.  * All other rights reserved.
  21.  * 
  22.  * This example is provided "as-is" and is subject to change; no
  23.  * warranties are made.  All use is at your own risk. No liability or
  24.  * responsibility is assumed.
  25.  *
  26.  ************************************************************************** 
  27.  *
  28.  * Swap_Buttons.c
  29.  *
  30.  * This example swaps the function of the left and right mouse buttons
  31.  * The C code is just the wrapper that installs and removes the
  32.  * input.device handler that does the work.
  33.  *
  34.  * The handler is written in assembly code since it is important that
  35.  * handlers be as fast as possible while processing the input events.
  36.  *
  37.  *
  38.  * Compile and link as follows:
  39.  *
  40.  * SAS C 5.10:
  41.  *
  42.  *  LC -b1 -cfirst -v -w Swap_Buttons.c
  43.  *
  44.  * Adapt assemble:
  45.  *
  46.  *  HX68 InputHandler.a to InputHandler.o
  47.  *
  48.  * BLink:
  49.  *
  50.  *  BLink from LIB:c.o+Swap_Buttons.o+InputHandler.o LIB LIB:lc.lib LIB:amiga.lib TO Swap_Buttons
  51.  *
  52.  */
  53.  
  54. #include <exec/types.h>
  55. #include <exec/memory.h>
  56. #include <exec/interrupts.h>
  57. #include <devices/input.h>
  58. #include <intuition/intuition.h>
  59.  
  60. #include <clib/exec_protos.h>
  61. #include <clib/alib_protos.h>
  62. #include <clib/intuition_protos.h>
  63.  
  64. #include <stdio.h>
  65.  
  66. #ifdef LATTICE
  67. int CXBRK(void) { return(0); }     /* Disable SAS CTRL/C handling */
  68. int chkabort(void) { return(0); }  /* really */
  69. #endif
  70.  
  71.  
  72. UBYTE NameString[]="Swap Buttons";
  73.  
  74. struct NewWindow mywin={50,40,124,18,0,1,CLOSEWINDOW,
  75.                         WINDOWDRAG|WINDOWCLOSE|SIMPLE_REFRESH|NOCAREREFRESH,
  76.                         NULL,NULL,NameString,NULL,NULL,0,0,0,0,WBENCHSCREEN};
  77.  
  78. extern VOID ButtonSwap();
  79.  
  80. extern struct IntuitionBase *IntuitionBase;
  81.  
  82. /*
  83.  * This routine opens a window and waits for the one event that
  84.  * can happen (CLOSEWINDOW)  This is just to let the user play with
  85.  * the swapped buttons and then close the program...
  86.  */
  87. VOID WaitForUser(VOID)
  88. {
  89. struct Window  *win;
  90.  
  91. if (IntuitionBase=(struct IntuitionBase *)
  92.                                 OpenLibrary("intuition.library",33L))
  93.     {
  94.     if (win=OpenWindow(&mywin))
  95.         {
  96.         WaitPort(win->UserPort);
  97.         ReplyMsg(GetMsg(win->UserPort));
  98.  
  99.         CloseWindow(win);
  100.         }
  101.     CloseLibrary((struct Library *)IntuitionBase);
  102.     }
  103. }
  104.  
  105. VOID main(VOID)
  106. {
  107. struct IOStdReq  *inputReqBlk;
  108. struct MsgPort   *inputPort;
  109. struct Interrupt *inputHandler;
  110.  
  111. if (inputPort=CreatePort(NULL,NULL))
  112.     {
  113.     if (inputHandler=AllocMem(sizeof(struct Interrupt),
  114.                                MEMF_PUBLIC|MEMF_CLEAR))
  115.         {
  116.         if (inputReqBlk=(struct IOStdReq *)CreateExtIO(inputPort,
  117.                                                  sizeof(struct IOStdReq)))
  118.             {
  119.             if (!OpenDevice("input.device",NULL,
  120.                              (struct IORequest *)inputReqBlk,NULL))
  121.                 {
  122.                 inputHandler->is_Code=ButtonSwap;
  123.                 inputHandler->is_Data=NULL;
  124.                 inputHandler->is_Node.ln_Pri=100;
  125.                 inputHandler->is_Node.ln_Name=NameString;
  126.                 inputReqBlk->io_Data=(APTR)inputHandler;
  127.                 inputReqBlk->io_Command=IND_ADDHANDLER;
  128.                 DoIO((struct IORequest *)inputReqBlk);
  129.  
  130.                 WaitForUser();
  131.  
  132.                 inputReqBlk->io_Data=(APTR)inputHandler;
  133.                 inputReqBlk->io_Command=IND_REMHANDLER;
  134.                 DoIO((struct IORequest *)inputReqBlk);
  135.  
  136.                 CloseDevice((struct IORequest *)inputReqBlk);
  137.                 }
  138.             else
  139.                 printf("Error: Could not open input.device\n");
  140.  
  141.             DeleteExtIO((struct IORequest *)inputReqBlk);
  142.             }
  143.         else
  144.             printf("Error: Could not create IORequest\n");
  145.  
  146.         FreeMem(inputHandler,sizeof(struct Interrupt));
  147.         }
  148.     else
  149.         printf("Error: Could not allocate interrupt struct memory\n");
  150.  
  151.     DeletePort(inputPort);
  152.     }
  153. else
  154.     printf("Error: Could not create message port\n");
  155. }
  156.